1
我想將daterun索引的重採樣(小時)熊貓數據框轉換爲元組。下面是數據框:從熊貓數據框丟失日期索引
ratetype p_rate v_rate
daterun
2013-10-24 13:00:00 1 0
2013-10-24 14:00:00 3 0
2013-10-24 15:00:00 5 0
2013-10-24 16:00:00 7 1
In [67]: type(df_p)
Out[67]: pandas.core.frame.DataFrame
我使用轉換成元組:
tuples = [tuple(x) for x in df_p.values]
我的問題是,該日期不包括在元組數組:
In [69]: tuples
Out[69]:
[(1, 0),
(3, 0),
(5, 0),
(7, 1)]
哪有我包括日期列以便最終:
In [69]: tuples
Out[69]:
[(2013-10-24 13:00:00, 1, 0),
(2013-10-24 13:00:00, 3, 0),
(2013-10-24 13:00:00, 5, 0),
(2013-10-24 13:00:00, 7, 1)]
如果日期時間格式不同,我不介意。