A data scientist is working in a Databricks notebook and wants to quickly generate a statistical summary of a PySpark DataFrame sensor_df that includes count, mean, standard deviation, min, and max for all numeric columns. Which of the following approaches is the MOST straightforward way to accomplish this?
- A. sensor_df.summary()
- B. sensor_df.describe()✓ Correct
- C. dbutils.data.summarize(sensor_df)
- D. sensor_df.printSchema()
Explanation
sensor_df.describe() returns count, mean, stddev, min, and max for all numeric (and string) columns, which is exactly what is requested. sensor_df.summary() also works but additionally includes percentile statistics (25%, 50%, 75%) that go beyond the basic set described — describe() is the more direct match to the stated requirements. dbutils.data.summarize(sensor_df) produces a richer, notebook-rendered profile (including histograms and null counts), which is more than what was asked and is a Databricks-specific utility rather than a standard API call. printSchema() only shows column names and data types, not any statistical summaries.