VOOZH about

URL: https://www.geeksforgeeks.org/python/getting-frequency-counts-of-a-columns-in-pandas-dataframe/

⇱ Count Frequency of Columns in Pandas DataFrame - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Count Frequency of Columns in Pandas DataFrame

Last Updated : 3 Oct, 2025

Counting how often each value appears in a column is a basic step in exploring your dataset. It helps you understand data distribution and identify patterns. Here are four common ways to count frequencies in a Pandas DataFrame.

1. Using value_counts()

The simplest method is value_counts(), which returns a Series with unique values as index and their counts as values.

Output

👁 Screenshot-2025-04-14-152958
Count frequency

You can use normalize=True to get relative frequencies or ascending=True to sort counts in ascending order.

2. Using groupby() with size()

When you want to group data by a specific column and count the frequency of each group, groupby() combined with size() is used for it.

Output

👁 Screenshot-2025-04-14-153451
Using groupby with size

The groupby() method can also be extended to multiple columns to count the frequency of values across combinations of categories.

3. Using crosstab()

For counting occurrences across two or more categories, crosstab() is useful. crosstab() provides a table format which is helpful for cross-dimensional analysis.

Output

👁 Screenshot-2025-04-14-153935
Using crosstab

Explanation:

  • pd.crosstab(): Creates a cross-tabulation table that counts occurrences of values.
  • index=df['Fruits']: Uses the unique values in the Fruits column as the rows of the table.
  • columns='count': Creates a single column labeled 'count' to store the frequency of each fruit.

4. Using a Pivot Table

A pivot table is another tool in Pandas which can be used to calculate frequency counts. It works well if we're looking to summarize data across multiple dimensions.

Comment
Article Tags:
Article Tags: