QuestionQ109

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

The code block below contains an error. It is intended to return a new DataFrame containing the mean of column sqft from DataFrame storesDF in a column named sqftMean. Identify the error.

storesDF.agg(mean("sqft").alias("sqftMean"))  
Explanation

The intended aggregate expression supplies a Column object to mean, created with col("sqft"), and aliases the resulting aggregate column as sqftMean: storesDF.agg(mean(col("sqft")).alias("sqftMean")). agg() correctly returns the one-row aggregated DataFrame.

Learn more

Community Discussion

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