1
我有一个数据帧,P
,格式:熊猫转换分钟数索引(0到1440),以日期时间
0 1 2
0 10088.245329 9905.462496 12328.830197
1 10092.783624 9688.034026 11785.442316
2 10312.043154 9501.677065 11784.126068
3 10314.919339 9694.886693 11419.465596
...
1438 9636.005396 9544.771643 14181.272599
1439 9414.292352 9312.184926 13988.822708
索引表示一天的分钟。
我想重新格式化为datatime对象,以便我可以将数据转换为半小时的数据。
我一直在玩的to_datetime
功能做到这一点:
P.index=pd.to_datetime(P.index,format='%M')
这个工程得到分钟,但不正确的小时:
<class 'pandas.tseries.index.DatetimeIndex'>
[1900-01-01 00:00:00, ..., 1900-01-01 00:59:00]
有谁知道如何做到这一点?
编辑:
我设法做到这一点:
pd.to_datetime([(str(int(x))+' '+str(y)) for x,y in zip(np.floor(P.index/60),P.index%60)],format='%H %M')
<class 'pandas.tseries.index.DatetimeIndex'>
[1900-01-01 00:00:00, ..., 1900-01-01 23:59:00]
Length: 1440, Freq: None, Timezone: None
我有一种感觉,有虽然一个更好的办法?