Problems / Fill Null Values / Editorial
COALESCE(value, default) is the standard SQL function for replacing NULLs. It evaluates its arguments left-to-right and returns the first non-NULL value.
COALESCE(value, default)
```sql
SELECT
product_id, name,
COALESCE(category, 'Uncategorized') AS category,
COALESCE(price, 0) AS price,
COALESCE(discount, 0) AS discount
FROM products
```
In PySpark, F.coalesce() works the same way. Use F.lit() to wrap literal default values.
F.coalesce()
F.lit()
Solve Fill Null Values yourself →