Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rhshadrach opened this issue Jan 13, 2023 · 4 comments · Fixed by #52395
Closed
Labels
Apply Apply, Aggregate, Transform, Map Bug Groupby

Comments

@rhshadrach
Copy link
Member

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.

@rhshadrach rhshadrach added Bug Groupby Apply Apply, Aggregate, Transform, Map labels Jan 13, 2023
@rhshadrach rhshadrach changed the title BUG: groupby.agg ignores as_index=False when BUG: groupby.agg ignores as_index=False after subset to a single column Jan 13, 2023
@rhshadrach rhshadrach changed the title BUG: groupby.agg ignores as_index=False after subset to a single column BUG: groupby.agg with mutliples ignores as_index=False after subset to a single column Jan 13, 2023
@tpackard1
Copy link
Contributor

@rhshadrach are you working on this? If not I would like to take it.

@rhshadrach
Copy link
Member Author

I think this will be easier to fix after a PR I'm working on which changes how .groupby(..., as_index=False)['b'] behaves. I would recommend holding off until then (it should be up next week sometime). I'll ping you here when that's done.

@rhshadrach
Copy link
Member Author

The PR is #50744, but still needs some minor fixups and review.

@luke396
Copy link
Contributor

luke396 commented Apr 4, 2023

   a  sum  mean
0  1    7   3.5
1  2    5   5.0

For now, it looks nice in main branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Bug Groupby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants