使用python / pandas填写缺少的日期,从每周到每天

时间:2017-11-26 20:15:44

标签: python pandas

我有这个数据框,我想每周重复一次,直到下周才重复

输入

Week          Netflix: (Worldwide)
2012-12-02    50
2012-12-09    51

输出

Week        Netflix: (Worldwide)
2012-12-02  50
2012-12-03  50
2012-12-04  50
2012-12-05  50
2012-12-06  50
2012-12-07  50
2012-12-08  50
2012-12-09  51

1 个答案:

答案 0 :(得分:6)

使用resample()

x is _not_ an instance of some abstract class that extends Parent?

来自@Wen的替代解决方案:

In [129]: df.set_index('Week').resample('1D').ffill().reset_index()
Out[129]:
        Week  Netflix: (Worldwide)
0 2012-12-02                    50
1 2012-12-03                    50
2 2012-12-04                    50
3 2012-12-05                    50
4 2012-12-06                    50
5 2012-12-07                    50
6 2012-12-08                    50
7 2012-12-09                    51