Learning path: Explore a Dataset Before You Model · Step 1 of 6
First Look at a Dataset: 6 Checks Before You Plot or Model
Six quick pandas checks that tell you what's inside a dataset: size, types, gaps, spread, label balance and duplicates. Shown on 142,193 days of Australian weather.
What you will learn
- Run the six pandas checks on a new dataset: shape, dtypes, isnull, describe, value_counts and duplicated
- Turn missing-value counts into percentages to judge each gap
- Explain why an imbalanced label makes accuracy misleading
- Explain why a real project explores the training part only
Before you start
- Basic Python
- Reading a CSV with pandas
Before you plot anything or train a model, you should know what's actually inside your data. A doctor checks your pulse, temperature and blood pressure before any diagnosis. We do the same with a dataset, in six quick checks.
None of these checks fix anything. They just tell you where to look. Let's run them on a real, messy dataset: Rain in Australia, with 142,193 days of weather.
The six checks
- How big is it?
shape - Numbers or text?
dtypes - What is missing?
isnull().sum() - How are the numbers spread?
describe() - How balanced is the label?
value_counts() - Is any row in twice?
duplicated()
Load the data
We use four datasets in this course. Three are tidy. The weather one is where the surprises are.
import pandas as pd
iris = pd.read_csv("iris.csv")
tips = pd.read_csv("tips.csv")
insurance = pd.read_csv("insurance.csv")
weather = pd.read_csv("weatherAUS.csv")
sets = {"iris": iris, "tips": tips, "insurance": insurance, "weather": weather}
for name, d in sets.items():
r, c = d.shape
print(f"{name:10} {r:>7} rows {c:>2} cols")
iris 150 rows 5 cols
tips 244 rows 7 cols
insurance 1338 rows 7 cols
weather 142193 rows 24 cols
Checks 1 and 2: size and types
print(weather.shape) # (142193, 24)
weather.dtypes.value_counts()
float64 17
str 7
Seventeen columns hold numbers and seven hold text. That matters, because the text columns will need turning into numbers before a model can use them.
Check 3: what is missing?
This is the most important check. Here's what happens inside it. isnull() asks every cell one question: is it missing? You get a table of True and False. Then sum() counts the True cells in each column.
isnull() marks every NaN as True and sum() counts them: 5, 5 and 0. On the whole table the same two steps give one count per column.counts = weather.isnull().sum()
missing = counts.sort_values(ascending=False)
missing.head(5)
Sunshine 67816
Evaporation 60843
Cloud3pm 57094
Cloud9am 53657
Pressure9am 14014
Counts are hard to judge on their own, so divide by the number of rows:
(missing.head(5) / len(weather) * 100).round(1)
| Column | % missing |
|---|---|
| Sunshine | 47.7 |
| Evaporation | 42.8 |
| Cloud3pm | 40.2 |
| Cloud9am | 37.7 |
| Pressure9am | 9.9 |
Almost half the days have no sunshine value, and four columns miss more than a third of their values. We can't ignore that. We'll decide how to handle it in the preprocessing section.
Check 4: how are the numbers spread?
cols = ["MinTemp", "MaxTemp", "Rainfall", "Humidity3pm"]
weather[cols].describe().round(1)
MinTemp MaxTemp Rainfall Humidity3pm
count 141556.0 141871.0 140787.0 138583.0
mean 12.2 23.2 2.3 51.5
min -8.5 -4.8 0.0 0.0
50% 12.0 22.6 0.0 52.0
max 33.9 48.1 371.0 100.0
Two things jump out:
- The count row is below 142,193 in every column. That's the gaps again.
- Rainfall has a median of 0 and a maximum of 371 mm. Most days are dry and a few days pour. That's a skewed column, and it will matter when we scale features.
Check 5: is the label balanced?
Our label is RainTomorrow. Passing normalize=True gives shares instead of counts.
label = weather["RainTomorrow"]
label.value_counts(normalize=True).round(3)
No 0.776
Yes 0.224
Compare that with iris, which has exactly 50 flowers of each species. The weather label is imbalanced.
Why balance matters: the lazy model
Imagine a model that says "no rain" every single day:
always_no = (label == "No").mean()
print(round(always_no, 3)) # 0.776
It scores 77.6% accuracy and finds zero rainy days. A high accuracy can still be useless when one answer is common. Keep this in mind when we get to the confusion matrix.
Check 6: is any row in twice?
print("weather ", weather.duplicated().sum()) # 0
print("insurance", insurance.duplicated().sum()) # 1
insurance[insurance.duplicated(keep=False)]
age sex bmi children smoker region charges
195 19 male 30.59 0 no northwest 1639.5631
581 19 male 30.59 0 no northwest 1639.5631
Same age, BMI, region and charge. A typing slip, or two real people? We can't tell for sure. drop_duplicates() would leave 1,337 rows. One repeat in 1,338 changes very little, so we keep the table as it is. On your own data, always ask the question.
One rule: explore the training part only
In a real project, split the data into train and test first, then explore only the train part. Every choice you make while looking (which columns to keep, how to fill the gaps) is learned from what you see. If you peek at the test part, it quietly leaks into those choices.
In this section we look at whole datasets to learn the techniques. A real project splits first.
Quick recap
| Question | pandas | Rain in Australia |
|---|---|---|
| How big? | shape | 142,193 rows, 24 columns |
| What types? | dtypes | 17 numeric, 7 text |
| What's missing? | isnull().sum() | Sunshine 47.7% missing |
| How spread? | describe() | Rainfall median 0, max 371 |
| Label balanced? | value_counts() | 77.6% No, 22.4% Yes |
| Duplicates? | duplicated() | 0 (insurance has 1) |
Try it yourself
Run the same six checks on the tips dataset. Is anything missing or repeated? Is the smoker column balanced?
The notebook and all four datasets for this lesson are in the StudyEasy AI Community. It's free to join, and you can post your answers there.
Built this? Share your solution in the StudyEasy AI Community.
Join free on Skool →StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Machine Learning Engineer: From First Model to ML Engineer
Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (opens in a new tab)Related articles
Plotting Distributions with seaborn: Histograms, KDE, Counts and log1p
Look at one column at a time: read the peak and the tail of a histogram, compare groups with hue, count categories, and tame a long tail with log1p. Shown on restaurant bills and iris flowers.
Scatter Plots and Pair Plots: See How Two Columns Relate
Draw one dot per row with seaborn scatterplot, colour the dots by group with hue, turn a clean split into a one-line rule, and read every pair at once with pairplot. Shown on iris and tips.
Finding Outliers: Box Plots, Violin Plots and the IQR Rule
Read a box plot from its five numbers, flag outliers with the 1.5 x IQR rule in pandas, compare groups with box and violin plots, and cap extreme values with clip. Shown on 244 restaurant bills.
Correlation and Heatmaps: Covariance, df.corr() and What They Miss
Put one number on "these two columns move together": why covariance depends on units, how correlation fixes it, scanning every pair with df.corr() and a seaborn heatmap, and the two traps correlation can't see.