Databricks Machine Learning Associate Question 146
Single answerYou are working with a Spark DataFrame named sales_data containing columns product_id, sales_amount, and quantity_sold. You need to compute summary statistics for the numeric columns using the .summary() method. Which of the following statements about the .summary() method is correct?
- A
The
.summary()method computes statistics such as mean, standard deviation, min, and max for all columns, including non-numeric ones. - B
The
.summary()method computes statistics such as mean, standard deviation, min, and max only for numeric columns. - C
By default, the
.summary()method returns statistics such as count, mean, stddev, min, and max. - D
The
.summary()method requires you to explicitly specify which summary statistics to compute, such as 'mean' or 'min'.
Show answer and explanation
Correct answer: C
Explanation
The .summary() method in Spark DataFrames is used to compute descriptive statistics for numeric columns. By default, it calculates statistics such as count, mean, standard deviation (stddev), minimum (min), and maximum (max). Non-numeric columns are ignored by default, and you don't need to explicitly specify these statistics unless you want additional ones like custom percentiles.
- A. Incorrect.
Incorrect: The
.summary()method computes statistics only for numeric columns, not for all columns including non-numeric ones. - B. Incorrect.
Incorrect: While
.summary()focuses on numeric columns, this option does not fully describe its behavior. - C. Correct.
Correct: By default, the
.summary()method returns statistics such as count, mean, stddev, min, and max for numeric columns. - D. Incorrect.
Incorrect: The
.summary()method does not require explicit specification of statistics; it computes a default set of statistics unless additional arguments are provided.