How do you handle missing values in pandas?
beginnerAnswer
First measure the problem: df.isnull().sum() for counts, or df.isnull().mean() for the proportion — 2% missing and 60% missing call for different responses.
Then choose. dropna(subset=['revenue']) removes rows missing a specific field. fillna() substitutes a value — zero, the median, or a category like 'Unknown'.
The important part is that every choice is an assumption. Filling revenue with zero asserts the sale was zero; filling with the median asserts it was typical. They give different answers, so the choice should be deliberate and documented.
Worth adding: bare df.dropna() removes a row for a single missing value anywhere in it, which on a wide table can silently discard most of the data.
Related