Skip to content

9. Replace Missing Values

Difficulty: Easy · Topics: Null Handling

The products table has gaps. Return all columns with:

An empty string "" is not a missing value.

Row order does not matter; column names must match. Your code is graded on 3 test cases, including hidden edge cases.

Sample data

products

idnamecategoryprice
1PenStationery1.5
2Notebooknull3
3MugKitchennull
4Lampnullnull

Expected output

idnamecategoryprice
1PenStationery1.5
2NotebookUnknown3
3MugKitchen0
4LampUnknown0

Hints

Hint 1df.fillna({"col": value}) accepts a dict of per-column defaults.
Hint 2Alternatively use F.coalesce(col, F.lit(default)) inside withColumn.

Learn the concepts

PySpark functions you'll practise

Related problems

Browse

Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings · Data Lake · Lakehouse · Streaming · Data Prep for AI · Spark Performance

Difficulty: Easy · Medium · Hard · Learn · All problems · dbt practice