Categories
Python Answers

How to count frequency of values in Python Pandas DataFrame column?

Spread the love

Sometimes, we want to count frequency of values in Python Pandas DataFrame column.

In this article, we’ll look at how to count frequency of values in Python Pandas DataFrame column.

How to count frequency of values in Python Pandas DataFrame column?

To count frequency of values in Python Pandas DataFrame column., we can use the value_counts method.

For instance, we write

counts = df['status'].value_counts().to_dict()
print(counts)

to call value_counts on the df data frame’s status column to count all the items in the status column.

And then we call to_dict to return the item as the keys and the count of each item in status as the values.

Conclusion

To count frequency of values in Python Pandas DataFrame column., we can use the value_counts method.

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 *