Skip to content

BUG: Grouper specified by key not regarded as in-axis #50413

Closed
@rhshadrach

Description

@rhshadrach

Currently using as_index=False only includes in-axis groupers (see #49519). Defining a Grouper by the key argument is in-axis, but not regarded as such.

df = pd.DataFrame({'a': [1, 1, 2], 'b': [1, 1, 2], 'c': [3, 4, 5]})
gb = df.groupby([pd.Grouper(key='a'), pd.Grouper(key='b')], as_index=False)
result = gb.sum()
print(result)
#    c
# 0  7
# 1  5

gb2 = df.groupby(['a', 'b'], as_index=False)
result2 = gb2.sum()
print(result2)
#    a  b  c
# 0  1  1  7
# 1  2  2  5

The 1st case above should match the output of the 2nd case.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions