Once missing values are identified, a Data Analyst has two primary remedies:
dropna): Remove rows or columns containing nulls (best when missingness is tiny, e.g. < 2%).fillna): Replace missing values with domain-appropriate surrogates (mean, median, mode, forward-fill, or a sentinel constant).df.dropna)how='any' (Default): Drops a row if even one column is null.how='all': Drops a row only if all columns are null.subset=['ColA', 'ColB']: Checks for nulls only in specified critical columns.axis=1: Drops entire columns containing nulls.df.fillna)In financial and numerical datasets, imputing with the median is preferred over the mean because the median is robust to extreme outliers:
In time-series and sensor data, use ffill() (propagate last valid observation forward) or bfill() (propagate next valid observation backward):
df.dropna()?df.ffill() method do?fillna() allows updating the original DataFrame directly without reassigning?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Detecting Missing Values (isna, notna, isnull) | Handling Duplicates & Data Type Conversions |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Combine 15 complete courses, 150 chapters, 541 topics, live SQL/Power BI/Tableau dashboards, and Scikit-Learn capstones at MSK Institute Shikohabad or Live Online.