Skip to main content

How do you deal with missing values in a dataset?

Machine learning basics · Beginner 3

Short answer

First find out why values are missing, because that decides the fix. Then drop rows or columns only if little is lost, impute with the median, most frequent value or a model, and often add a flag saying the value was missing. Fit any imputation on training data only.

Deeper answer

Missing can carry meaning: a blank income field on a loan application may itself predict risk, so a missing-value indicator often helps. Values missing completely at random are the easy case; values missing for a reason need care.

In pandas, start with isna().sum() to see how much is missing per column. Use a scikit-learn pipeline with SimpleImputer so cross-validation refits it per fold. Gradient boosting libraries can handle missing values natively, which is worth mentioning.

What a strong answer covers

Answer it out loud in the mock interview about 1 min

Follow-ups to expect

Common mistakes

Learn it

Tables with pandas

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.