← Pandas
Lesson 4 of 5
Cleaning data
Watch, read the card, then practise. Missing values · Duplicates · Changing types
The video for this lesson is being recorded.
Meanwhile, the notes below and the 60-second cards cover the same ideas.
Practise this topicMissing values
Missing values show up as NaN. Find them, then drop or fill them.
Remember: Count missing values before you decide what to do.
Duplicates
Duplicate rows can double-count your data. Find them and drop them.
Remember: Decide what makes a row 'the same' before dropping.
Changing types
Columns sometimes load with the wrong type, like numbers stored as text. Convert them.
Remember: Check df.dtypes: maths on text columns won't work.
Try the example in Code Lab
import pandas as pd import numpy as np s = pd.Series([80, np.nan, 90]) print(int(s.isna().sum()), s.fillna(s.mean()).tolist())