每月到每日的值

问题描述

我有一个每月值,我想更改为每日数据;

Date        Ireland    UK   France
01/09/2020  42         87   84
01/10/2020  85         45   65
01/11/2020  45         42   89
01/12/2020  45         15   41
01/01/2020  34         41   35

但是希望每天都这样。每个月值代表该月内的每日值。

例如


Date       Ireland    UK   France
01/09/2020 42         87   84
02/09/2020 42         87   84
03/09/2020 42         87   84
.
.
.
.
06/10/2020 85         45  65
07/10/2020 85         45  65

etc

任何帮助,不胜感激!

解决方法

投射到日期时间,然后将resample与向前填充一起使用:

df['Date'] = pd.to_datetime(df.Date,format='%d/%m/%Y')
df.set_index('Date').resample('D').ffill()

            Ireland  UK  France
Date                           
2020-01-01       34  41      35
2020-01-02       34  41      35
2020-01-03       34  41      35
2020-01-04       34  41      35
2020-01-05       34  41      35
...             ...  ..     ...
2020-11-27       45  42      89
2020-11-28       45  42      89
2020-11-29       45  42      89
2020-11-30       45  42      89
2020-12-01       45  15      41