Pandas rolling apply function to entire window dataframe Pandas rolling apply function to entire window dataframe pandas pandas

Pandas rolling apply function to entire window dataframe


Not with pd.DataFrame.rolling .... that function is applied iteratively to the columns, taking in a series of floats/NaN, and returning a series of floats/NaN, one-by-one. I think you'll have better luck with your intuition....

def rolling_pipe(dataframe, window, fctn):    return pd.Series([dataframe.iloc[i-window: i].pipe(fctn)                       if i >= window else None                       for i in range(1, len(dataframe)+1)],                     index = dataframe.index) df.pipe(rolling_pipe, 3, lambda x: x.shape)