Course overviewGoogle Search · Clean values and create columns
Handle missing values
Identify missing values, keep known observations, and choose when filling or dropping is appropriate.
Step 1 of 3 · Learn
Find missing values
Use .isna() to identify missing values and .notna() to identify present values. Do not compare with None or NaN using ==; zero and an empty string are not missing values.
index
name
label
0
Ari
NA
1
Bo
2
Cam
A
↓
index
name
label
0
Ari
NA
Only the missing label matches. The empty string is still a present value.
Drop only the rows you mean to drop
dropna(subset=[...]) removes rows missing values in the specified columns. Without subset, an unrelated missing value can remove a row you intended to keep.
index
name
label
0
Ari
NA
1
Bo
2
Cam
A
↓
index
name
label
1
Bo
2
Cam
A
Check only label; keep both rows where that value is present.
Fill labels without inventing facts
fillna() replaces missing values; a column-name dictionary limits which columns change. A display label can use "Unknown", but never fill anonymous user IDs with a shared ID or turn an unknown measurement into zero without justification.
index
name
label
0
Ari
NA
1
Bo
2
Cam
A
↓
index
name
label
0
Ari
Unknown
1
Bo
2
Cam
A
Only the missing label changes. This is a display choice, not a recovered fact.
▷ Your turn
Return search_id, user_id, and query for searches whose user_id is missing. Keep the missing values and source row order. Save the DataFrame as result.