Closed
Description
xref #9959
When subsetting the columns of a dataframe after a groupby to a series:
df = pd.DataFrame({'a': [1], 'b': [2], 'c': [3]}).set_index('a')
g = df.groupby('a')['b']
the public-facing groupby arguments axis
and as_index
are not passed on to the resulting SeriesGroupBy
.
I think the following two examples should probably behave the same:
g = df.groupby('a', as_index=False)['b']
g2 = df['b'].groupby('a', as_index=False)
but the first produces
b
0 2
And the 2nd deliberately raises TypeError: as_index=False only valid with DataFrame
.
Note that the arguments axis
and as_index
are only meant for DataFrames, and as such, I think a line such as
g = df.groupby('a', as_index=False)['b']
should raise.