Counting and Spotting Values
value_counts, unique, and quick checks.
Counting and Spotting Values is a free Data Science Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Data Science Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Get to Know Your Column
Before any analysis, you want a feel for what is inside a Series. A few quick methods summarize the contents in seconds. 🔍
A Sample Series
Here is a Series of fruit names with some repeats. We will explore its contents with handy built-in methods.
import pandas as pd
s = pd.Series(['apple', 'pear', 'apple', 'fig', 'pear', 'apple'])Count Each Value
The value_counts method tallies how often each value appears, sorted from most to least common. It is the fastest frequency check.
print(s.value_counts())See the Distinct Set
Call unique to get every distinct value just once, in the order first seen. It answers what kinds of values you have.
print(s.unique())How Many Distinct
The nunique method returns the count of distinct values as a single number. Here it tells you how many fruit kinds exist.
print(s.nunique())Shares Instead of Counts
Add normalize=True to value_counts and you get proportions instead of raw counts. Now each fruit's share sums to one.
print(s.value_counts(normalize=True))Spot Missing Values
The isna method flags each value that is missing as True. Summing those flags counts the gaps in your column at a glance.
nums = pd.Series([1.0, None, 3.0])
print(nums.isna().sum())Check Membership
Use isin with a list to test which values belong to a chosen set. It returns a boolean mask you can filter with later.
print(s.isin(['apple', 'fig']))Find the Extremes
For numbers, max and min surface the largest and smallest values instantly, without sorting the whole Series yourself.
print(nums.max(), nums.min())One-Shot Overview
The describe method bundles count, unique, top, and frequency for text, giving a tidy snapshot in a single call. 📋
print(s.describe())Your Inspection Toolkit
Together these methods are your first inspection pass on any column. A minute spent here saves hours of confused analysis later. 🧰
Quick Check
Pick the right tool for a frequency tally.
Recap
You can now profile a Series with value_counts, unique, nunique, isna, and isin. These quick checks reveal what your data holds. Well done! 🎉
Frequently asked questions
Is the “Counting and Spotting Values” lesson free?
Yes — the full text of “Counting and Spotting Values” is free to read here on the web, and the Data Science Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Data Science Academy course, upgrade to CoddyKit PRO.
What will I learn in “Counting and Spotting Values”?
value_counts, unique, and quick checks. You practise Data Science Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Data Science Academy?
No prior experience is required. Data Science Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Counting and Spotting Values” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Data Science Academy lesson?
Yes. Every Data Science Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- A Column With a Name and Index
- Label-Based vs Position-Based Access
- Series Math and Alignment
- Counting and Spotting Values