Skip to content

Why is there no mode method for groupby objects? #13809

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
connerxyz opened this issue Jul 26, 2016 · 2 comments
Closed

Why is there no mode method for groupby objects? #13809

connerxyz opened this issue Jul 26, 2016 · 2 comments
Labels
Duplicate Report Duplicate issue or pull request Groupby

Comments

@connerxyz
Copy link

There is mean, max, median, min and mad yet no mode for groupby objects. Is there a good reason? What if I add and issue pull-request?

@sinhrks
Copy link
Member

sinhrks commented Jul 26, 2016

related to #11562. Nice to discuss how the output should be.

@jreback
Copy link
Contributor

jreback commented Jul 26, 2016

yes, closing as a duplicate of that issue.

The crus is that mode is not a reducer (like sum, mean) and such, nor is it a straight filter, like nth, or tail. Its like .value_counts which we don't directly support either via groupby

you can do this:

In [6]: df = DataFrame({'A' : [1,2,1,2], 'B' : [1,1,1,1]})

In [7]: df
Out[7]: 
   A  B
0  1  1
1  2  1
2  1  1
3  2  1

In [8]: df.groupby('A').B.value_counts()
Out[8]: 
A  B
1  1    2
2  1    2
Name: B, dtype: int64

In [9]: df.groupby('A').B.apply(lambda x: x.mode())
Out[9]: 
A   
1  0    1
2  0    1
Name: B, dtype: int64

@jreback jreback closed this as completed Jul 26, 2016
@jreback jreback added the Duplicate Report Duplicate issue or pull request label Jul 26, 2016
@jreback jreback added this to the No action milestone Jul 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Groupby
Projects
None yet
Development

No branches or pull requests

3 participants