Count Frequency of Columns in Pandas DataFrame Last Updated : 03 Oct, 2025 Comments Improve Suggest changes 8 Likes Like Report 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. Python import pandas as pd data = { 'Fruits': ['Apple', 'Banana', 'Apple', 'Orange', 'Banana', 'Apple', 'Orange'], 'Quantity': [3, 2, 3, 1, 2, 3, 1] } df = pd.DataFrame(data) fruit_counts = df['Fruits'].value_counts() # Counts how many times each unique fruit appears in the 'Fruits' column print(fruit_counts) OutputCount 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. Python fruit_counts = df.groupby('Fruits').size() print(fruit_counts) OutputUsing groupby with sizeThe 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. Python fruit_counts = pd.crosstab(index=df['Fruits'], columns='count') print(fruit_counts) OutputUsing crosstabExplanation: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 TableA 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. Python fruit_counts = df.pivot_table(index='Fruits', aggfunc='size') print(fruit_counts) OutputUsing Pivot TableRelated Articles:Pandas TutorialCount Frequency of Columns in Pandas DataFrame Create Quiz Comment N NishitJain Follow 8 Improve N NishitJain Follow 8 Improve Article Tags : Python Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like