A silver order lines table must report a quantity of 0 and a discount of 0.0 where the bronze data has nulls in those two numeric columns. Other numeric columns, such as unit_price, must keep their nulls so data stewards can investigate them. Which PySpark call should the data engineer use?
Choose one.
fillna can take a dictionary of column-to-value pairs so each column gets its own default.
fillna({"quantity": 0, "discount": 0.0}) fills only the two named columns. An unscoped fillna(0) also changes unit_price, dropna removes rows instead of filling them, and na.replace replaces existing values rather than nulls.
- Identify which columns need a default and which must keep nulls.
- Choose fillna, because the rows must stay.
- Pass a dictionary so only the named columns are filled.
Exam tip: fillna({col: value}) fills only the columns you name.
Cleaning, Joining and Reshaping Data with PySpark and SQL (Databricks Data Engineer Associate) — the lesson that teaches this.