每月到每日值
Monthly to Daily values
我有一个月度值,我想将其更改为每日数据;
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
我有一个月度值,我想将其更改为每日数据;
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