Skip to content

BUG: groupby.agg with mutliples ignores as_index=False after subset to a single column #50724

Closed
@rhshadrach

Description

@rhshadrach
df = pd.DataFrame({'a': [1, 1, 2], 'b': [3, 4, 5]})
gb = df.groupby('a', as_index=False)['b']
result = gb.agg(["sum", "mean"])
print(result)
#    sum  mean
# a           
# 1    7   3.5
# 2    5   5.0

In the output, a should be a column rather than in the index.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ApplyApply, Aggregate, Transform, MapBugGroupby

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions