ESSAY / NOTE

df.resample 错误 TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but

运行df.resample()更改K线时间间隔,将5minK线转变为15minK线的过程中,出现如题错误。 period_df = df.resample(rule= rule_type, on='candle_begin_time_GMT8').agg({ 'open':'first', 'high':'max', }) 1 2 3 4 问题解释 因为用于作为改变的时间on需要是时间戳等时间单位,而在此处,df数据中candle_begin_time_GMT8这一列数据是str格式,所以如题。 问题解决 df['candle_begin_time_GMT8'] = pd.to_datetime(df['candle_begin_time_GMT8']) 原文 https://blog.csdn.net/The_Time_Runner/article/details/86619766 我的解决方法 df['Datetime'] = pd.to_datetime(df['Datetime']) df.set_index('Datetime', inplace=True)