I have a dataframe df
that contains data in periods of 3 hours:
index , values
2003-01-01 00:00:00, 2.0
2003-01-01 03:00:00, 1.8
2003-01-01 06:00:00, 1.4
2003-01-01 09:00:00, 1.1
....
I want to resample the data to every hour and interpolate the missing values in between linearly. I can achieve something similar, filling the missing values with .bfill()
, and it looks like this:
df2 = df.resample('H').bfill()
I tried to alter this to achive my task as follows:
df2 = df.resample('H')
df2.interpolate(method='linear', axis=0, inplace=True)
But df2 = df.resample('H')
in contrast to df2 = df.resample('H').bfill()
doesn't return a dataframe object, but a pandas.core.resample.DatetimeIndexResampler object
.
Do you know how I can do the resampling and interpolation? Do you have some other work around? Tnx