value_counts()

noun

say it: “VAL-yoo KOWNTS” /ˈvælju ˈkaʊnts/

A pandas method that counts how many times each different value appears in a column, with the most common first.

What does value_counts() do in pandas?

value_counts() counts how many rows hold each value of a column, most common first. It counts rows, not the amounts in another column. normalize=True gives each value's share of the rows, from 0 to 1, instead of the count.

import pandas as pd
sales = pd.DataFrame({"category": ["produce", "honey", "produce", "crafts", "produce", "honey"]})
sales["category"].value_counts()    # produce 3, honey 2, crafts 1

In a sentence

  • “With normalize=True, value_counts() gave each category's share of the sales.”
  • “value_counts() showed that produce was on more rows than any other category.”

Level: Apprentice · More Python terms at this level

Updated