value_counts() is the standard, one-call way to build a frequency table for a categorical column — it's essentially grouping the column by its own unique values and taking each group's size, combined with sorting, packaged into a single convenient method. Passing normalize=True returns proportions, each count divided by the total, instead of raw counts, which is useful for quickly seeing the relative percentage breakdown of categories rather than absolute numbers.
1Understanding df.value_counts()
value_counts() is the standard, one-call way to build a frequency table for a categorical column — it's essentially grouping the column by its own unique values and taking each group's size, combined with sorting, packaged into a single convenient method. Passing normalize=True returns proportions, each count divided by the total, instead of raw counts, which is useful for quickly seeing the relative percentage breakdown of categories rather than absolute numbers.
Pass normalize=True to value_counts() to get each category's proportion of the total directly, instead of computing raw counts and then manually dividing each by the total yourself.
import pandas as pd
df = pd.DataFrame({"status": ["active", "active", "pending", "active", "cancelled"]})
print(df["status"].value_counts())2Practical Example
Here is a real-world application of df.value_counts() showing how it is used in production Pandas code.
import pandas as pd
df = pd.DataFrame({"status": ["active", "active", "pending", "active", "cancelled"]})
print(df["status"].value_counts(normalize=True))3Best Practices
Follow these guidelines when working with df.value_counts():
1. Use value_counts() for a quick frequency breakdown of a categorical column, instead of a manual groupby-and-size or a Counter from the collections module
2. Pass normalize=True when proportions/percentages are more useful for your analysis than raw counts
3. Chain value_counts() with .head(n) to see just the most common categories when there are too many unique values to display usefully all at once
Tip: Pass normalize=True to value_counts() to get each category's proportion of the total directly, instead of computing raw counts and then manually dividing each by the total yourself.
import pandas as pd
df = pd.DataFrame({"status": ["active", "active", "pending", "active", "cancelled"]})
print(df["status"].value_counts())