Skip to content

BUG: groupby drops columns if the column name is the same as the grouper #8112

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
behzadnouri opened this issue Aug 25, 2014 · 0 comments · Fixed by #8585
Closed

BUG: groupby drops columns if the column name is the same as the grouper #8112

behzadnouri opened this issue Aug 25, 2014 · 0 comments · Fixed by #8585
Milestone

Comments

@behzadnouri
Copy link
Contributor

>>> df = pd.DataFrame(np.random.randint(1, 9, (2, 3)), columns=['jim', 'joe', 'jolie'])
>>> df
   jim  joe  jolie
0    4    7      8
1    7    8      3
>>> ts = df['joe'] * 0
>>> ts.name
'joe'
>>> gr = df.groupby(ts)
>>> gr.nth(0)  # this invokes _set_selection_from_grouper internally
     jim  jolie
joe
7      4      8
>>> gr.apply(sum)  # joe column is gone
     jim  jolie
joe
0     11     11

whereas:

>>> df.groupby(ts).apply(sum)
     jim  joe  jolie
joe
0     11   15     11

What happens is that this line removes the column from selection if it has the same name as the grouper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants