Why can\'t I use an offset when rolling
a multi-index DataFrame? For example, with:
rng = pd.date_range(\'2017-01-03\', period
In order to use an offset like '30D' you need a simple date index. In this case the simplest way to achieve that is to move 'Name' out of the index with reset_index(level='Name')
, leaving you with only 'Date' as the index:
df['Avg'] = df.reset_index(level='Name').groupby(['Name'])['Vals'].rolling('30D').mean()