Databricks Machine Learning Associate Question 152
Select 2You are working on a Databricks notebook and need to compute summary statistics (e.g., mean, variance, min, max) for a Spark DataFrame. The DataFrame is stored as a Delta table, and you want to save the summary statistics to a CSV file in the Databricks File System (DBFS). Which of the following steps should you take to achieve this?
- A
Use the
describemethod on the Spark DataFrame to compute summary statistics. - B
Use the
dbutils.fs.putmethod to save the summary statistics directly as a CSV file. - C
Convert the output of the
describemethod to a Pandas DataFrame and useto_csvto write the file to DBFS. - D
Write the results of the
describemethod directly to a Delta table using thewritemethod. - E
Use the
dbutils.fs.cpmethod to copy the summary statistics from a notebook cell output to a DBFS location.
Show answer and explanation
Correct answers: A, C
Explanation
To compute and save summary statistics in Databricks, you use the describe method of a Spark DataFrame to generate the statistics. The output can then be converted to a Pandas DataFrame using .toPandas() and written to a CSV file in DBFS using the to_csv method. Other methods like dbutils.fs.put or dbutils.fs.cp are not designed for handling DataFrame objects or statistical outputs.
- A. Correct.
Correct. The
describemethod on a Spark DataFrame is specifically designed to compute summary statistics such as mean, variance, min, and max. - B. Incorrect.
Incorrect. The
dbutils.fs.putmethod is used for writing strings to files in DBFS, but it cannot directly handle DataFrame objects or summary statistics. - C. Correct.
Correct. Converting the output of the
describemethod to a Pandas DataFrame allows you to use itsto_csvmethod to write the summary statistics to a CSV file on DBFS. - D. Incorrect.
Incorrect. The
describemethod output is not suitable for direct writing to a Delta table, as it is not in a tabular format compatible with Delta Lake. - E. Incorrect.
Incorrect. The
dbutils.fs.cpmethod is used for copying files between locations in DBFS but cannot be used to save computed statistics from a notebook cell output directly.