Count how often each distinct value appears in a column.
value_counts is usually the second thing you run on an unfamiliar dataset, right after head. It tells you what is in a column, how lopsided it is, and whether the categories are as tidy as you assumed — which, with real data, they rarely are.
Official documentation: Series.value_counts
The forms worth knowing
# Counts, largest first (the default)
df['Status'].value_counts()
# Proportions instead of raw counts
df['Status'].value_counts(normalize=True)
# Include missing values, which are excluded by default
df['Status'].value_counts(dropna=False)
# Ordered by value rather than by frequency
df['Status'].value_counts().sort_index()
# Combinations across several columns
df.value_counts(['Region', 'Status'])
That last form — calling it on the data frame rather than a column — counts unique combinations, which is often what you actually want.
A worked example, on real data
Netflix published an engagement report listing every title watched over six months. Bamboo Weekly #45 used it.
A natural first question: how much of the catalog is actually available worldwide?
import pandas as pd
url = ('https://www.bambooweekly.com/content/files/4cd45et68cgf/1HyknFM84ISQpeua6TjM7A/'
'97a0a393098937a8f29c9d29c48dbfa8/'
'what_we_watched_a_netflix_engagement_report_2023jan-jun.xlsx')
(
pd.read_excel(url, skiprows=5, usecols=['Available Globally?'])
['Available Globally?']
.value_counts()
)
Which gives:
Available Globally?
No 13700
Yes 4514
Three quarters of the titles are region-locked. That is a one-line finding from 18,214 rows, and it reframes any analysis that follows — comparing global hours to regional hours without knowing this split would be misleading.
Add normalize=True and you get 0.752 and 0.248 instead, which is often the number you actually want to quote.
Three mistakes people make
Forgetting that missing values are dropped by default. value_counts() silently excludes NaN, so the counts may not sum to len(df). If the gaps matter — and in real data they usually do — pass dropna=False and see them.
Reading it as a data frame when it is a series. The result is a series indexed by the distinct values, so result['Yes'] works but result['Available Globally?'] raises a KeyError. Chain .reset_index() if you want a two-column frame.
Trusting the categories to be clean. Real data gives you Yes, yes, and Y as three separate entries. value_counts is precisely the tool that reveals this — treat an unexpectedly long result as a finding about your data, not a nuisance.
Practice it
Work through a value_counts exercise, with instant feedback and no signup required: practice.lernerpython.com/bamboo-weekly/value-counts/
Go deeper
Bamboo Weekly is the practice. If you want the structured version — full courses with downloadable Jupyter notebooks, plus live Pandas office hours when you get stuck — that is LernerPython+Data. A paid Bamboo Weekly subscription is included with it.
See it on real data
Below are the 71 Bamboo Weekly exercises that use value_counts on real-world data — try each one, then study the worked solution.
- Bamboo Weekly #182: Surveillance technology
- Bamboo Weekly #172: World Cup
- Bamboo Weekly #171: Hantavirus
- Bamboo Weekly #169: Press freedom
- Bamboo Weekly #168: US gas prices
- Bamboo Weekly #167: Oil prices
- Bamboo Weekly #163: Daylight saving time
- Bamboo Weekly #162: Spotify and car accidents
- Bamboo Weekly #161: Missiles in Israel
- Bamboo Weekly #159: State of the Union
- Bamboo Weekly #158: University endowments
- Bamboo Weekly #157: Government corruption
- Bamboo Weekly #152: Congestion pricing
- Bamboo Weekly #144: Museum Heists
- Bamboo Weekly #142: Hurricanes
- Bamboo Weekly #140: Stack Overflow survey
- Bamboo Weekly #138: Federal workers
- Bamboo Weekly #137: UN Security Council
- Bamboo Weekly #132: JetBrains survey
- Bamboo Weekly #129: Tom Lehrer
- Bamboo Weekly #124: NATO Spending
- Bamboo Weekly #123: Missiles
- Bamboo Weekly #121: Research funding
- Bamboo Weekly #120: Pennies
- Bamboo Weekly #119: Python conferences
- Bamboo Weekly #106: Flu season
- Bamboo Weekly #105: Federal employees
- Bamboo Weekly #104: Aviation accidents
- Bamboo Weekly #102: WordPress
- Bamboo Weekly #97: Drones
- Bamboo Weekly #96: Taylor Swift
- Bamboo Weekly #94: Strategic Wine Reserve
- Bamboo Weekly #92: Climate disaster costs
- Bamboo Weekly #90: Voter participation
- Bamboo Weekly #87: Nuclear power
- Bamboo Weekly #86: FEMA
- Bamboo Weekly #79: Cyber attacks
- Bamboo Weekly #77: Paris Olympics
- Bamboo Weekly #76: Aging legislators
- Bamboo Weekly #74: UK elections
- Bamboo Weekly #73: Avocado hand
- Bamboo Weekly #72: City travel
- Bamboo Weekly #71: Holidays
- Bamboo Weekly #70: Moon missions
- Bamboo Weekly #68: Dangerously hot weather
- Bamboo Weekly #66: Pittsburgh
- Bamboo Weekly #65: Microplastics
- Bamboo Weekly #64: Coal power
- Bamboo Weekly #63: Ukraine aid
- Bamboo Weekly #61: Solar eclipse
- Bamboo Weekly #55: IVF
- Bamboo Weekly #54: Household debt
- Bamboo Weekly #52: Border encounters
- Bamboo Weekly #51: Academy Awards
- Bamboo Weekly #49: Campaign finance
- Bamboo Weekly #48: Aviation accidents
- Bamboo Weekly #46: Pedestrians
- Bamboo Weekly #45: Netflix
- Bamboo Weekly #43: Financial protection
- Bamboo Weekly #42: Plant hardiness
- Bamboo Weekly #41: Wine production
- Bamboo Weekly #36: Nobel Prize
- Bamboo Weekly #34: House of Representatives
- Bamboo Weekly #33: Fracking
- Bamboo Weekly #29: Auto accidents
- Bamboo Weekly #21: Electric cars
- Bamboo Weekly #13: Python developers
- Bamboo Weekly #11: Software jobs
- Bamboo Weekly #7: Bank failures
- Bamboo Weekly #5: Ukrainian exports
- Bamboo Weekly #3: Earthquake
Part of the Pandas Methods Index. See also practice by skill.