Python 3.x 如何将数据帧重新采样到秒槽中

Python 3.x 如何将数据帧重新采样到秒槽中,python-3.x,pandas,Python 3.x,Pandas,我有这个数据框: 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:仅对DatetimeInde

我有这个数据框:

    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:仅对DatetimeIndex、TimedeltaIndex或periodinex有效,但得到了一个“RangeIndex”实例


我还将
DateTime
转换为DateTime类型,方法是执行
dfd['DateTime']=pd.to_DateTime(dfd['DateTime'])
,但它仍然给出相同的错误

您需要使用
dfd.reset\u index('DateTime',inplace=True)
将DateTime放入索引。以下是手册中的注释:

频率转换和时间重采样的简便方法 series.Object必须具有类似datetime的索引, PeriodIndex或TimedeltaIndex),或将类似datetime的值传递给 on或level关键字。“