Skip to main content
PYSPARK โ€ข LESSON 67

Imputing Defaults with fillna()

How do we replace missing numeric and string values with custom default values using a dictionary?

Intermediateโฑ 2 Minutesโญ 340 XP
๐Ÿค” THE QUESTION

How do we replace missing numeric and string values with custom default values using a dictionary?

๐Ÿ’ก WHAT IS IT?

fillna() substitutes NULL entries with specified constants, either across all columns or using a column-to-value map.

๐ŸŽฏ WHAT IS IT USED FOR?

Imputing missing features for machine learning and ensuring reporting dashboards display clean fallback labels.

๐Ÿ’ป EXAMPLE
df = df.fillna({"age": 0, "status": "UNKNOWN"})

๐ŸŽฏ Mission Objectives

Practice typing production-grade PySpark code for Imputing Defaults with fillna().

  • โœ“ Pass dictionary mapping to fillna()
  • โœ“ Impute default age and status
  • โœ“ Cleanse missing values in-place