0

我有这个数据框:

    DateTime
0   2020-04-04 10:15:40
1   2020-04-04 10:15:56
2   2020-04-04 11:07:11
3   2020-04-04 11:08:14
4   2020-04-04 11:18:46
.    .
.    .

我想将此数据帧重新采样到秒箱(范围更短)。

我试过:我的数据报dfd.resample('30S')[0:5]在哪里dfd,但它给了我TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex'.

我也DateTime通过做转换为日期时间类型,dfd['DateTime'] = pd.to_datetime(dfd['DateTime'])但它仍然给我同样的错误。

4

1 回答 1

1

您需要使用 DateTime 将其放入索引dfd.reset_index('DateTime', inplace=True)。这是手册中的评论:

“时间序列频率转换和重采样的便捷方法。对象必须具有类似日期时间的索引(DatetimeIndex、PeriodIndex 或 TimedeltaIndex),或者将类似日期时间的值传递给 on 或 level 关键字。”

于 2020-05-16T17:17:15.473 回答