我有以下数据框
df = pd.DataFrame(data=[np.nan,1.34,np.nan,1,3,np.nan,np.nan,4,5,2,3,4],
index=[datetime.date(2015, 3, 31),
datetime.date(2015, 3, 31),
datetime.date(2015, 3, 31),
datetime.date(2015, 3, 31),
datetime.date(2015, 4, 1),
datetime.date(2015, 4, 1),
datetime.date(2015, 4, 1),
datetime.date(2015, 4, 3),
datetime.date(2015, 4, 3),
datetime.date(2015, 4, 5),
datetime.date(2015, 4, 5),
datetime.date(2015, 4, 5)])
运行
np.unique(df.index)
我得到了
array([datetime.date(2015, 3, 31), datetime.date(2015, 4, 1),
datetime.date(2015, 4, 3), datetime.date(2015, 4, 5)], dtype=object)
即。缺少日期datetime.date(2015, 4, 2)
datetime.date(2015, 4, 4)
如何更改日期以保持连续日期?
我想:
DF
df
Out[28]:
0
2015-03-31 NaN
2015-03-31 1.34
2015-03-31 NaN
2015-03-31 1.00
2015-04-01 3.00
2015-04-01 NaN
2015-04-01 NaN
2015-04-02 4.00
2015-04-02 5.00
2015-04-03 2.00
2015-04-03 3.00
2015-04-03 4.00
2015-04-03成为2015-04-02等等......