Closed
Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
If
df = pandas.DataFrame()
df['date'] = pandas.date_range('2021-1-1', '2021-1-5', freq='h')
df.loc[df.date <= '2021-1-3', 'category'] = 'A'
df.loc[df.date > '2021-1-3', 'category'] = 'B'
df.set_index(['category','date'], inplace=True)
df['value'] = 1
then
df.groupby('category').rolling('D', on='date')
breaks with
ValueError: invalid on specified as date, must be a column (of DataFrame), an Index or None
Problem description
The documentation states that the on
argument can be a MultiIndex
level (and then confusingly adds "rather than the DataFrame's index").
Expected Output
rolling
should accept a MultiIndex
level. Interestingly,
df.groupby('category').resample('D', level='date')
works, but it would be nice to unify the interfaces: resample
accepts level
and on
for index and column respectively, while rolling
accepts on
for both.