concept summary() in category pyspark

appears as: summary()
Data Analysis with Python and PySpark

This is an excerpt from Manning's book Data Analysis with Python and PySpark.

describe() is a fantastic method, but what if you want more? summary() at the rescue!

Where describe() will take *cols as a parameter (one or more columns, the same way as select() or drop()), summary() will take *statistics as a parameter. This means that you’ll need to select the columns you want to see before passing the summary() method. On the other hand, we can customize the statistics we want to see. By default, summary() shows everything describe() shows, adding the approximate 25%-50% and 75% percentiles. Listing 4.17 shows how you can replace describe() for summary() and the result of doing so.

Listing 4.17. Summarizing everything in one fell swoop: default or custom options.
for i in logs.columns:
    logs.select(i).summary().show()  #1

# +-------+------------------+
# |summary|      LogServiceID|
# +-------+------------------+
# |  count|           7169318|
# |   mean|3453.8804215407936|
# | stddev|200.44137201584468|
# |    min|              3157|
# |    25%|              3291|
# |    50%|              3384|
# |    75%|              3628|
# |    max|              3925|
# +-------+------------------+
#
# [... many more slightly larger tables]

for i in logs.columns:
    logs.select(i).summary("min", "10%", "90%", "max").show()  #2

# +-------+------------+
# |summary|LogServiceID|
# +-------+------------+
# |    min|        3157|
# |    10%|        3237|
# |    90%|        3710|
# |    max|        3925|
# +-------+------------+
#
# [...]

If you want to limit yourself to a subset of those metrics, summary() will accept a number of string parameters representing the statistic. You can input count, mean, stddev, min or max directly. For approximate percentiles, you need to provide them in XX% format, such as 25%.