Databricks Certified Associate Developer for Apache Spark — Question 172

Which of the following code blocks returns a new DataFrame with the mean of column sqft from DataFrame storesDF in column sqftMean?

Answer options

Correct answer: D

Explanation

The correct answer is D, as it properly utilizes the agg function to compute the mean of the sqft column and assigns it a new column name sqftMean. Option A incorrectly uses withColumn instead of agg, while options B and C do not correctly reference the column for the mean calculation with col(). Option E also uses withColumn, which is not suitable for this aggregation task.