Categories
Python Answers

How to count the frequency that a value occurs in a Python Pandas dataframe column?

Spread the love

To count the frequency that a value occurs in a Python Pandas dataframe column, we call groupby and count.

For instance, we write

df = pd.DataFrame({'a':list('abssbab')})
df.groupby('a').count()

to create the df data frame.

Then we call groupby with 'a' to group the 'a' column values into groups.

Then we call count to count the number of values in each group.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *