How can I calculate a rolling window sum in pandas across this MultiIndex dataframe? I can't work out how to get the moving annual sum from this data:

&gt;                          revenue
&gt; txdate   2014-01-31     2014-02-28      2014-03-31     2014-04-30     ....
&gt; user_id
&gt; 1            0              10             165             0
&gt; 2          265             265             200           250
&gt; 3          770             985            1235           900
&gt; ....


Previously I would have tried something like this and adjusted until it worked:

df.groupby(level='practice_id').apply(lambda x: pd.rolling_sum(x, 12))


but it's deprecated and I'm not getting my head around the 0.18 changes to rolling despite reading the docs, and I'm not sure that the shape of the data is helpful (it's close to what needs to be inserted in a db table). The original data format is as follows:

&gt; txdate          user_id        tx_amount
&gt; 2014-01-01         2               5
&gt; 2014-01-02         2               5
&gt; 2014-01-02         3              30
&gt; 2014-01-03         3              15
&gt; 2014-01-02         2              10


I reshaped with the following cmd:

&gt; df.set_index('txdate').groupby('user_id').resample('M').agg({'revenue': np.sum})


I'm thinking I might need to reverse the order of operations.
If anyone else comes looking, this was my solution:

# find last column
last_column = df.shape[1]-1

# grab the previous 11 columns (also works if there aren't that many in the df)
wanted = df.iloc[:, (last_column-11):last_column]

# calculate the rounded moving annual total 
mat_calc = round(wanted.sum(axis=1)/len(wanted.columns), 2)


Probably not the most pandastic solution, but it works well.