Getting more value from the Pandas’ value_counts()

Five ways to effectively use the value_counts() function in Python

Parul Pandey
Towards Data Science
4 min readOct 22, 2019

--

Data exploration is an important aspect of the Machine Learning pipeline. Before we decide which model to train and how many to train, we must have an idea of what our data contains. The Pandas library is equipped with a number of useful functions for this very purpose and value_counts is one of them. This function returns the count of unique items in a pandas dataframe. However, most of the time, we end up using value_counts with the default parameters. So in this short article, I’ll show you how to achieve more by altering the default parameters.

value_counts()

The value_counts() method returns a Series containing the counts of unique values. This means, for any column in a dataframe, this method returns the count of unique entries in that column.

Syntax

Series.value_counts()

Parameters

--

--

Principal Data Scientist @H2O.ai | Author of Machine Learning for High-Risk Applications