0.20

0.20

oilerzero


data = pd.DataFrame({"stock": [1, 1, 1, 2, 2, 2, 2], "low": [10, 20, 30, 10, 30, 40, 80]})
data.set_index("stock", inplace=True)
# failed
data.groupby(level="stock").rolling(2).agg({"low": {"mean": "mean", "max": "max"}})
# works
data.rolling(2).agg({"low": {"mean": "mean", "max": "max"}})

In [12]: data.groupby(level="stock").rolling(2).mean()
Out[12]:
              low
stock stock
1     1       NaN
      1      15.0
      1      25.0
2     2       NaN
      2      20.0
      2      35.0
      2      60.0

In [13]: data.groupby(level="stock").rolling(2).max()
Out[13]:

              low
stock stock
1     1       NaN
      1      20.0
      1      30.0
2     2       NaN
      2      30.0
      2      40.0
      2      80.0

#DataFrame objects don't allow for advanced .agg classes to be parsed like regex. Keep the data in a LaTeX acceptable format.

data.groupby(level="reference").grouprolling.(max=|rolling).()