I used to use this formula to compute the derivative of a signal recorded every seconds, after applying a rolling mean to it.
df.rolling(rollingWindow, center=True).mean().diff(rollingWindow).shift(int(-rollingWindow/2)) / (rollingWindow/60)
Now, I'd like to do the same, but based on the index values which are a timestamp with not constant intervals between each others.
As mentioned by DYZ, using df.resample()
, I obtain the following if I resample every 5 seconds and compute a rolling average over 5 minutes :
rollingWindow = int(5*60/5)
df.resample('5S').pad().rolling('5T', min_periods=10).mean().diff(rollingWindow)/5