How to Count the Frequency of Values in a Column in Pandas?

Spread the love

Problem –

You want to count how many times certain values appear in a column in pandas.

Solution –

To count the frequency of values in a column in pandas you can use the pandas value_counts() method.

Let’s read a dataset to illustrate it.

import pandas as pd

url = 'https://raw.githubusercontent.com/bprasad26/lwd/master/data/Restaurant.csv'
df = pd.read_csv(url)
df.head()

Now, suppose I want to count how many restaurants gets the Good, Very Good and Excellent rating, I can use the value_counts() method.

df['Quality Rating'].value_counts()

Rating: 1 out of 5.

Leave a Reply