Last Updated : 11 Jul, 2025
Pandas is one of the most widely used library for data handling and analysis. It simplifies many data manipulation tasks especially when working with tabular data. In this article, we'll explore the Series.value_counts()
function in Pandas which helps you quickly count the frequency of unique values in a Series.
The value_counts()
method returns a Series containing the count of unique values in the original Series. By default it sorts the result in descending order and show the most frequent values first. The syntax of function is:
Parameters:Series.value_counts(normalize=False, sort=True, ascending=False, bins=None, dropna=True)
normalize
: Show the results as percentages instead of counts by setting this to True
.sort
: Sorts the values by frequency by showing most common first. Set to False
to keep the original order.ascending
: Set to True
if you want to see the least frequent values first instead of the most frequent.bins
: For numeric data this groups the values into ranges like 0–10, 10–20. Useful for continuous numbers.dropna
: Skips missing (NaN
) values by default. Set to False
if you want to include them in the result.Here we are creating a sample series.
Python
import pandas as pd
sr = pd.Series(['New York', 'Chicago', 'Toronto', 'Lisbon', 'Rio', 'Chicago', 'Lisbon'])
print(sr)
Output:
Data SeriesNow we will use
Series.value_counts()
function to find the values counts of each unique value in the given Series object.
Output:
Unique String ValuesAs we can see in the output the Series.value_counts() function returned the value counts for each unique value in the given Series object..
Example 2: Counting Numeric Values withNaN
Python
import pandas as pd
sr = pd.Series([100, 214, 325, 88, None, 325, None, 325, 100])
print(sr)
Output:
Python
Output:
Numeric values with NanAs we can see in the output Series.value_counts()
function has returned the value counts of each unique value in the given Series object.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4