QuestionQ131

VerifiedTroubleshooting and Tuning Apache Spark DataFrame API Applications.

The code block below contains an error. It is intended to return a new DataFrame in which missing values in the sqft column of DataFrame storesDF are replaced with 30,000. Identify the error.

A sample of DataFrame storesDF is shown below:

Question Image

Code block:

storesDF.na.fill(30000, col("sqft"))  
Explanation

PySpark's DataFrameNaFunctions.fill(value, subset) is valid for replacing null values, but subset must be a column name string or a tuple/list of column-name strings. A Column object returned by col("sqft") is invalid for that parameter; use "sqft" or ["sqft"] instead.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!