Skip to content
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

unable to aggregate and summarize counts for a categorical variable #88

Open
dhairyadalal opened this issue Jun 21, 2019 · 1 comment
Open

Comments

@dhairyadalal
Copy link

So I want to be to simply do a group by and count on a column with categorical values. When running the code below

df = pd.DataFrame({"animal": ["cat", "cat", "dog", "dog"],
                   "breed": ["tabby", "short hair", "poodle", "pug"],
                   "age": [1,2,3,4]
                  })

df >> group_by(X.animal) >> summarize(count=n(X.name))

I run into a AttributeError: 'str' object has no attribute 'size' error.

In dplyr, this would be the equivalent of:

df %>% group_by(animal) %>% summarise(count = n())

@Ignaciovf
Copy link

The error message can be better than this, but you are counting by a column that does not exist. The following code yields the required result:
dfsd >> group_by(X.animal) >> summarize(count=n(X.animal))

animal count
0 cat 2
1 dog 2

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

No branches or pull requests

2 participants