nerdexam
Databricks

DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #57

The code block shown below should return a new DataFrame with the mean of column sqft from DataFrame storesDF in column sqftMean. Choose the response that correctly fills in the numbered blanks…

The correct answer is A. 1. agg. To compute a mean and return it in a named column, use agg() with the mean() function (from pyspark.sql.functions) and alias the result. The completed code is: storesDF.agg(mean('sqft').alias('sqftMean')). So blank 1 = agg, blank 2 = mean, blank 3 = 'sqft'. Option A correctly…

Perform data aggregation operations on Spark DataFrames

Question

The code block shown below should return a new DataFrame with the mean of column sqft from DataFrame storesDF in column sqftMean. Choose the response that correctly fills in the numbered blanks within the code block to complete this task. Code block:

storesDF.1(2(3).alias("sqftMean"))

Options

  • A
    1. agg
  • B
    1. withColumn
  • C
    1. agg
  • D
    1. mean
  • E
    1. agg

How the community answered

(39 responses)
  • A
    77% (30)
  • B
    3% (1)
  • C
    8% (3)
  • D
    10% (4)
  • E
    3% (1)

Explanation

To compute a mean and return it in a named column, use agg() with the mean() function (from pyspark.sql.functions) and alias the result. The completed code is: storesDF.agg(mean('sqft').alias('sqftMean')). So blank 1 = agg, blank 2 = mean, blank 3 = 'sqft'. Option A correctly identifies blank 1 as agg. Option B uses withColumn, which cannot apply aggregate functions meaningfully across an entire DataFrame. Options D uses mean as blank 1, which is not a DataFrame method in this position. mean is the function inside agg, not the top-level DataFrame method.

Topics

#Spark DataFrame API#Aggregation#PySpark#Data Transformation

Community Discussion

No community discussion yet for this question.

Full DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Practice