Cleaning data
Handle missing values, duplicates and wrong types deliberately.
What you will be able to do
- Count missing values before deciding.
- Drop duplicates with subset and keep rules.
- Convert types with astype or to_numeric.
- Document every cleaning decision.
In plain English
Cleaning is a series of explicit decisions. Dropping rows is sometimes right; filling with a median or a sentinel is sometimes right. Record why you chose each one so the analysis is reproducible.
import pandas as pd
df = pd.DataFrame({
'course': ['CSS', 'CSS', 'SQL', None],
'minutes': [18, 18, None, 9],
})
df = df.drop_duplicates()
df['minutes'] = df['minutes'].fillna(df['minutes'].median())
df = df.dropna(subset=['course'])
print(df)Your turn
EasyDrop incomplete rows
Remove rows where the course column is missing.
PYTHON · starter
df = df.dropna()Check your understanding before moving on.
Knowledge checkQuestion 1
What does fillna do?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.