Does anyone know an efficient function/method such as pandas.rolling_mean, that would calculate the rolling difference of an array
pandas.rolling_mean
This is my closest so
If you got KeyError: 0, try with iloc:
KeyError: 0
iloc
import pandas x = pandas.DataFrame({ 'x_1': [0, 1, 2, 3, 0, 1, 2, 500, ],}, index=[0, 1, 2, 3, 4, 5, 6, 7]) x['x_1'].rolling(window=2).apply(lambda x: x.iloc[1] - x.iloc[0])