Skip to content

Count Boolean values with .groupby() #21031

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
sursu opened this issue May 14, 2018 · 1 comment
Closed

Count Boolean values with .groupby() #21031

sursu opened this issue May 14, 2018 · 1 comment
Labels
Groupby Numeric Operations Arithmetic, Comparison, and Logical operations

Comments

@sursu
Copy link
Contributor

sursu commented May 14, 2018

Take the following dataframe:

df = pd.DataFrame({'ID':[1,2,1,1,2,3,4,4,4],
                   'Litmus':[False,False,True,True,False,False,True,True,True]})

I want to count the conditional number of True values, that is, I want to count the number of True values for each ID.

This works fine:
df.groupby('ID')['Litmus'].sum()

However, this does not:
df[4:7].groupby('ID')['Litmus'].sum()

To make it more interesting, this again works fine:
df[4:8].groupby('ID')['Litmus'].sum()

Bizarre behavior.

@jreback
Copy link
Contributor

jreback commented May 14, 2018

duplicate of #14873

pls show the actual return values, rather than 'Bizarre behavior' as well as versioning information as indicated in the template. The more complete reports are the better.

@jreback jreback closed this as completed May 14, 2018
@jreback jreback added Groupby Numeric Operations Arithmetic, Comparison, and Logical operations labels May 14, 2018
@jreback jreback added this to the No action milestone May 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Groupby Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

No branches or pull requests

2 participants