PySpark DataFrame summary() for String and Numeric Columns
Note: This question is part of a series of questions that present the same scenario. Each question in the series contains a unique solution that might meet the stated goals. Some question sets might have more than one correct solution, while others might not have a correct solution. After you answer a question in this section, you will NOT be able to return to it. As a result, these questions will not appear in the review screen. You have a Fabric tenant that contains a new semantic model in OneLake. You use a Fabric notebook to read the data into a Spark DataFrame. You need to evaluate the data to calculate the min, max, mean, and standard deviation values for all the string and numeric columns. Solution: You use the following PySpark expression: df.summary() Does this meet the goal?
Community Votes
55% of anonymous learners picked answer A. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
The question tests knowledge of PySpark's df.summary() function, specifically that it operates on both string and numeric columns, unlike pandas' default describe().
This page confirms that the PySpark df.summary() method correctly calculates summary statistics for both string and numeric columns. It establishes that the method meets the goal of evaluating data for min, max, mean, and standard deviation.
Choosing 'No' because mean and standard deviation are not applicable to string columns, failing to realize df.summary() still includes string columns and computes applicable statistics like min and max.
Community Discussion (12 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
Thedf.summary method in PySpark is explicitly designed to compute summary statistics for both numeric and string columns. For numeric columns, it calculates count, mean, stddev, min, max, and optional percentiles. For string columns, it calculates count, min, and max, returning null for inapplicable statistics like mean and stddev. Therefore, using df.summary successfully meets the goal of evaluating the data across all string and numeric columns.Why the Other Options Are Wrong
Option B suggests the goal is not met, which is incorrect. A common misconception is thatdf.summary ignores string columns entirely or fails if it cannot compute mean and stddev for them. While those specific statistical measures are undefined for strings, the method still processes string columns to find applicable statistics like min and max, fully satisfying the requirement to evaluate all column types.Community Comment Notes
Several commenters correctly noted thatdf.summary works on both string and numeric columns, with one stating "In PySpark, use df.summary for summary statistics of both numeric and string columns". Others argued against it because "mean and standard deviation are not applicable to string data", but the function gracefully handles this by returning null for those metrics while still evaluating the string columns. Another commenter incorrectly claimed "df.summary.show is correct", but the calculation occurs within the summary method itself. Official Reference
Exam Strategy
Remember that PySpark's df.summary() and df.describe() process both string and numeric columns, unlike pandas which defaults to numeric only. Do not assume the function fails on string columns just because some statistics are undefined.
Related Analysis
Practice All DP-600 Questions
Access 115 questions with complete answers and detailed explanations.
View Full DP-600 Practice Test →