7

I am dealing with a pandas dataframe and want to apply a custom function to windows of that dataframe. (both rows and columns)

For example, take this dataframe,

   A  B  C
0  1  4  7
1  2  5  8
2  3  6  9

what I want is for my custom function to be applied to the slice of window size 2 like this,

apply first function on,

0  1  4  7
1  2  5  8

then apply function on,

1  2  5  8
2  3  6  9

I looked into rolling window and tried this,

df.rolling(2).apply(my_function)

But the rolling.apply is only feeding a 1D array to my function. How can I feed all the columns?

I want to achieve this without looping.

Thanks

irobot96
  • 91
  • 4
  • https://stackoverflow.com/questions/38878917/how-to-invoke-pandas-rolling-apply-with-parameters-from-multiple-column – BENY Apr 24 '19 at 03:15

0 Answers0