I have a series of daily meteo data, and I would like to replace each daily value with the mean value for the month the day belongs to. To achieve this, I want to first downsample the dataframe to monthly mean, upsample it to daily frequency again. All this using Pandas 1.0.1.
The dataframe looks like this:
dframe =
2001-01-01 23.00000
2001-01-02 19.18034
2001-01-03 9.18034
2001-01-04 0.00000
2001-01-05 0.00000
2001-01-06 0.00000
2001-01-07 0.00000
2001-01-08 0.00000
2001-01-09 9.18034
2001-01-10 19.18034
2001-02-01 20.18034
2001-02-02 10.18034
2001-02-03 0.00000
2001-02-04 0.00000
2001-02-05 0.00000
2001-02-06 0.00000
2001-02-07 0.00000
2001-02-08 10.18034
2001-02-09 20.18034
2001-02-10 24.00000
After downsampling, things look alright (values may not be matching, these are dummy numbers):
means = dframe.resample(rule = 'M').mean()
means =
2001-01-31 8.456906
2001-02-28 7.499419
But the subsequent upsampling does not work as I would like it to:
segmented = means.resample(rule = 'D').bfill()
segmented =
2001-01-31 8.456906
2001-02-01 7.499419
2001-02-02 7.499419
2001-02-03 7.499419
2001-02-04 7.499419
... ...
The first period (January 2001) is not upsampled, while the second is.
I tried all combinations with the arguments closed and label and loffset and with bfill() and ffill(), but to no avail; sometimes it's the first month to be wrong and sometiems the last, but there's always a wrong one.
Help would be appreciated.