Skip to content

Groupby as index #4670

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

Merged
merged 2 commits into from
Aug 27, 2013
Merged

Groupby as index #4670

merged 2 commits into from
Aug 27, 2013

Conversation

hayd
Copy link
Contributor

@hayd hayd commented Aug 25, 2013

closes #4648
closes #3417
closes #4649 (pr)

In [1]: df = pd.DataFrame([[1, 2], [2, 3], [1, 4], [1, 5], [2, 6]], index=list('abcde'))

In [2]: g = df.groupby(0, as_index=False)

In [3]: g.apply(lambda x: x)
Out[3]: 
   0  1
a  1  2
b  2  3
c  1  4
d  1  5
e  2  6

In [4]: g.head(2)
Out[4]: 
   0  1
a  1  2
c  1  4
b  2  3
e  2  6

@@ -516,7 +516,7 @@ def _concat_objects(self, keys, values, not_indexed_same=False):
result = result.reindex(ax)
else:
result = result.reindex_axis(ax, axis=self.axis)
elif self.group_keys:
elif self.group_keys and self.as_index:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpcloud this seemed to do it!

@hayd
Copy link
Contributor Author

hayd commented Aug 27, 2013

@jreback also, this fix seems stupidly trivial, but ok to merge too?

I think there may be some more to do on the as_index thing (will keep a look out for similar) but this is a good start.

@jreback
Copy link
Contributor

jreback commented Aug 27, 2013

this closes all those? give you a prize of bang-for-the-buck!

go ahead (and stince as_index prob not used too much)..be on lookout

hayd added a commit that referenced this pull request Aug 27, 2013
@hayd hayd merged commit c320a15 into pandas-dev:master Aug 27, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

as_index is only applied to aggregators DataFrame.groupby(as_index=False).apply() ignores option and sets wrong indices
2 participants