Chapter 8 of 30

Keep learning and build your Data Science skills.

27%
Chapter 8

Handling Missing Values

Learn different approaches for dealing with missing data.

Theory

Missing values occur when information is unavailable for one or more observations. Common approaches include: • Removing rows • Removing columns • Filling with mean • Filling with median • Filling with mode • Using model-based imputation The best approach depends on the amount of missing data and the meaning of the feature.

Example

import pandas as pd

df = pd.DataFrame({
    "Age": [20, None, 30, 40]
})

df["Age"] = df["Age"].fillna(
    df["Age"].median()
)

print(df)

Output

The missing Age value is replaced using the median.

Practice

Compare mean and median imputation on a dataset containing missing values.

Interview Questions

1

What are missing values?

2

How can missing values be handled?

3

When can median imputation be useful?

Quick Quiz

Which option best describes this chapter?

A.Imputation or removal
B.Only HTML
C.Only SQL joins
D.Only image compression