I donβt think rolling_apply can be used to perform moving correlation, since it seems to split DataFrames into 1-dimensional arrays. There may be more efficient ways to do this, but one solution is to get the generator to give a slice for each window on its own:
def window(length, size=2, start=0): while start + size <= length: yield slice(start, start + size) start += 1
and then skip it.
In [144]: from pandas import DataFrame ...: import numpy as np ...: ...: df = DataFrame(np.arange(10).reshape(2,5).T, columns=['a','b']) ...: ...: df.iloc[0,1] = -1
source share