Learn / Pandas
Intermediate

Missing Data & Transformations

Finding and filling gaps, plus the vectorized way to change values.

CallBehaviorExample

df.dropna()

drop rows with ANY missing value

a 3-row df with 1 NaN row → 2 rows left

df.dropna(thresh=2)

keep rows with at least 2 non-missing values

row with only 1 non-null value gets dropped, others kept

df.fillna(0)

fill every gap with a constant

[1, NaN, 3][1, 0, 3]

df.interpolate()

fill gaps by linear interpolation

[1, NaN, 3][1, 2.0, 3]

For transforming values, vectorized operations beat .apply() almost every time: .apply() runs a real Python function call per row/element, which is much slower than an operation NumPy/pandas can run in a tight C loop.

Now practice it

Exercises that use what this lesson just covered.

Selection & FilteringGroupBy & Aggregation