我已从csv文件导入数据并获得了数据帧tmp4。并合并列“日期”和“时间”并设置索引。但是在使用重采样函数后,我得到“ TypeError:仅对DatetimeIndex,TimedeltaIndex或PeriodIndex有效,但得到了'Index'的实例”。如何纠正?谢谢。
tmp4['datetime']=tmp4[['date','time']].apply(lambda x : '{} {}'.format(x[0],x[1]), axis=1)
tmp4=tmp4.set_index('datetime')
tmp4['open']=tmp4['open'].resample('5min').first()
date time open high low close
datetime
2017-04-10 09:25:00 2017-04-10 09:25:00 20.72 20.72 20.72 20.72
2017-04-10 09:30:00 2017-04-10 09:30:00 20.72 20.72 20.67 20.67
2017-04-10 09:31:00 2017-04-10 09:31:00 20.66 20.67 20.62 20.63
2017-04-10 09:32:00 2017-04-10 09:32:00 20.63 20.65 20.59 20.59
2017-04-10 09:33:00 2017-04-10 09:33:00 20.59 20.59 20.52 20.52
2017-04-10 09:34:00 2017-04-10 09:34:00 20.53 20.58 20.52 20.58
2017-04-10 09:35:00 2017-04-10 09:35:00 20.58 20.59 20.56 20.58
2017-04-10 09:36:00 2017-04-10 09:36:00 20.58 20.58 20.53 20.53
2017-04-10 09:37:00 2017-04-10 09:37:00 20.53 20.55 20.53 20.55
2017-04-10 09:38:00 2017-04-10 09:38:00 20.55 20.56 20.54 20.55
2017-04-10 09:39:00 2017-04-10 09:39:00 20.54 20.56 20.54 20.55
2017-04-10 09:40:00 2017-04-10 09:40:00 20.55 20.56 20.54 20.55
2017-04-10 09:41:00 2017-04-10 09:41:00 20.56 20.57 20.55 20.56
2017-04-10 09:42:00 2017-04-10 09:42:00 20.56 20.59 20.56 20.59
2017-04-10 09:43:00 2017-04-10 09:43:00 20.58 20.63 20.58 20.63