[問題]資料補遺

作者: silencemars (mars)   2019-05-18 16:01:08
原始資料
2019/5/16 00:00 2019/5/16 00:00 0
2019/5/15 23:55 2019/5/16 00:00 0
2019/5/15 23:50 2019/5/16 00:00 0
2019/5/15 23:35 2019/5/15 23:36 0
2019/5/15 23:30 2019/5/15 23:31 0
2019/5/15 23:25 2019/5/15 23:26 0
2019/5/15 23:20 2019/5/15 23:21 0
2019/5/15 23:15 2019/5/15 23:16 0
想要補成
0 2019/5/16 00:00 2019/5/16 00:00 0
1 2019/5/15 23:55 2019/5/16 00:00 0
2 2019/5/15 23:50 2019/5/16 00:00 0
3 2019/5/15 23:45 null 0
4 2019/5/15 23:40 null 0
5 2019/5/15 23:35 2019/5/15 23:36 0
6 2019/5/15 23:30 2019/5/15 23:31 0
7 2019/5/15 23:25 2019/5/15 23:26 0
8 2019/5/15 23:20 2019/5/15 23:21 0
9 2019/5/15 23:15 2019/5/15 23:16 0
我是這樣寫
df = pd.DataFrame(pd.read_csv('004.csv',header=0))
df
idx = pd.period_range(min(df.DATA_TIME), max(df.DATA_TIME),freq='5T')
df1 =df.reindex(idx, fill_value=0)
df1
但是結果卻是
2019-05-15 23:15 0 0 0
2019-05-15 23:20 0 0 0
2019-05-15 23:25 0 0 0
2019-05-15 23:30 0 0 0
2019-05-15 23:35 0 0 0
2019-05-15 23:40 0 0 0
2019-05-15 23:45 0 0 0
2019-05-15 23:50 0 0 0
2019-05-15 23:55 0 0 0
2019-05-16 00:00 0 0 0
請問該怎寫比較好~~感謝各位大
作者: TitanEric (泰坦)   2019-05-18 19:10:00
看起來新的dataframe是對的 跟原本的join應該就可以了

Links booklink

Contact Us: admin [ a t ] ucptt.com