I am trying to get a fairly basic resampling method to work with a pandas data frame. My data frame df is indexed by datetime entries and contains prices
price
datetime
2000-08-16 09:29:55.755000 7.302786
2000-08-16 09:30:10.642000 7.304059
2000-08-16 09:30:26.598000 7.304435
2000-08-16 09:30:41.372000 7.304314
2000-08-16 09:30:56.718000 7.304334
I would like to downsample this to 5min. Using
df.resample(rule='5Min',how='last',closed='left')
takes the closest point to the left in my data of a multiple of 5min; similarly
df.resample(rule='5Min',how='first',closed='left')
takes the closes point to the right. However, I would like to take the linear interpolation between the point to the left and right instead, e.g. if my df contains the two consecutive entries
time t1, price p1
time t2, price p2
and
t1<t<t2 where t is a multiple of 5min
then the resampled dataframe should have the entry
time t, price p1+(t-t1)/(t2-t1)*(p2-p1)