How do we conditionally replace null category values with 'Uncategorized' while preserving valid strings?
Combining when(col.isNull(), ...) with otherwise(col) to standardize missing category fields.
Product catalog classification, taxonomy standardization, and reporting dimension cleansing.
from pyspark.sql.functions import col, when
df = df.withColumn(
"normalized_category",
when(col("category").isNull(), "Uncategorized")
.otherwise(col("category"))
)Practice typing production-grade PySpark code for Conditional NULL Handling with when().