A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/python-pandas-series-value_counts/ below:

Python | Pandas Series.value_counts() - GeeksforGeeks

Python | Pandas Series.value_counts()

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:

Series.value_counts(normalize=False, sort=True, ascending=False, bins=None, dropna=True)

Parameters: Example 1: Counting Unique String Values

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 Series

Now we will use Series.value_counts() function to find the values counts of each unique value in the given Series object.

Python

Output:

Unique String Values

As 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 with NaN 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 Nan

As 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