PySpark DataFrame describe() for String and Numeric Stats
Short answer
B Df.describe() does not calculate mean and standard deviation for string columns, so it does not meet the goal for all columns.
Question
Key Takeaways
Tests knowledge of df.describe() limitations: it excludes non-numeric data from statistical calculations like mean and stddev.
The PySpark df.describe() method computes statistics only for numeric columns. It does not calculate mean or standard deviation for string columns, making it insufficient for the stated goal.
Common mistake: Many assume describe() works for all column types because it returns count, min, and max for strings, ignoring that mean and stddev are undefined for text.
Expert Analysis
Why the Answer Is Correct
df.describe in PySpark is designed to compute basic statistics (count, mean, stddev, min, max) exclusively for numeric columns. For string columns, it typically only provides count, min, and max values. Since the requirement is to calculate mean and standard deviation for ALL string and numeric columns, this solution fails because those metrics cannot be meaningfully calculated for string data.Why the Other Options Are Wrong
Option A claims the solution meets the goal, which is incorrect. While df.describe.show runs without error, it does not produce mean or standard deviation for string columns, thus failing the specific requirement for all columns.Community Comment Notes
Several users like Gunstsings and Martin_Nbg incorrectly believe describe handles all stats for all columns. Others like maia01 and moteruky correctly identify that string columns lack mean/stddev support, confirming the answer is No. patricck also highlights the distinction between numeric and string applicability.Official Reference
This link opens the official vendor documentation in a new tab.
Exam Strategy
Always distinguish between descriptive statistics applicable to numeric vs. categorical data. If a question asks for mean/stddev on strings, the answer is almost always 'No' unless a custom UDF is specified.
Frequently Asked Questions
Why doesn't df.describe() work for string columns?
It only computes count, min, and max for strings. Mean and stddev are mathematically undefined for non-numeric data.
How to get stats for all columns in Spark?
Use summary() with explicit aggregation functions or filter columns by type before applying describe().
Community Votes
69% of anonymous learners picked answer A. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 9 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors, not of islever. The comments shown first are the most substantive of the thread — ranked by depth, community endorsement and relevance; expand the list below to read the rest.
From public community threads 9
-
Martin_Nbg 👍 14I think A is correct https://learn.microsoft.com/en-us/dotnet/api/microsoft.spark.sql.dataframe.describe?view=spark-dotnet
-
Gunstsings 👍 5 Answered ADataFrame.Describe = Computes basic statistics for numeric and string columns, including count, mean, stddev, min, and max. If no columns are given, this function computes statistics for all numerical or string columns.
-
zeeneuser 👍 4A is correct, confirming after trying the command from Notebook. Displays count as well in addition to min, max, mean, and standard deviation.
-
maia01 👍 4 Answered Bdescribe: only numeric columns with limited summary summary: numeric and non-numeric, broader summary
-
moteruky 👍 3It shows all stat for numeric values but shows only 3 stat for string(count,min and max, it doesnt account for mean and std)
Show 4 more comments
-
2fe10ed 👍 2 Answered Ahttps://spark.apache.org/docs/latest/api/python/reference/pyspark.sql/api/pyspark.sql.DataFrame.describe.html
-
jackjack1 👍 1 Answered ADescribe as other mentioned shows all fields asked for. if we were to use summary, we would have to specify what fields we want as shown here: https://learn.microsoft.com/en-us/dotnet/api/microsoft.spark.sql.dataframe.summary?view=spark-dotnet
-
patricck 👍 1There's a difference in numeric and string values. It's applicable for the numeric values but not for the string values and the question mentions both data
-
nappi1 👍 1 Answered Adf.describe().show() returns count, mean, stddev, min, max for all the columns (numeric and non numeric)
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.
Related Analysis
Practice All DP-600 Questions
Access 115 questions with complete answers and detailed explanations.
View Full DP-600 Practice Test →