resample()错误TypeError: Only valid with DatetimeIndex, Timedelta,but got an instance of 'Index'【已解决】

  • Pandas.df.resample()错误TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of ‘Index’【已解决】

  • 问题背景

运行df.resample()更改K线时间间隔,将5minK线转变为15minK线的过程中,出现如题错误。

period_df = df.resample(rule= rule_type, on='candle_begin_time_GMT8').agg({
    'open':'first',
    'high':'max',
})
  • 问题解释

因为用于作为改变的时间on需要是时间戳等时间单位,而在此处,df数据中candle_begin_time_GMT8这一列数据是str格式,所以如题。

  • 问题解决

df['candle_begin_time_GMT8'] = pd.to_datetime(df['candle_begin_time_GMT8'])

.
.
.
2019-01-24 00:31:38写于济南

你可能感兴趣的:(Error,小白学量化交易)