首页 > 解决方案 > 扩展数据框中数据的分辨率

问题描述

我有一个每月频率的数据框。该索引的时间戳为 1880-01-01、1880-02-01... 我想将索引扩展为 1880-01-01、1880-01-02...

完成此操作后,我想转发填充列中的数据,以便它重复自身,直到下一个数据可用。

此过程的目标是将该数据帧与其他具有每日分辨率的数据帧合并。

标签: pythonpandasdataframetime-series

解决方案


resample与 一起使用Resampler.ffill

df = pd.DataFrame({'col':[1,3]}, index=pd.to_datetime(['1880-01-01','1880-02-01']))

print (df)
            col
1880-01-01    1
1880-02-01    3

df1 = df.resample('d').ffill()
print (df1)

            col
1880-01-01    1
1880-01-02    1
1880-01-03    1
1880-01-04    1
1880-01-05    1
1880-01-06    1
1880-01-07    1
1880-01-08    1
1880-01-09    1
1880-01-10    1
...

推荐阅读