pyspark.sql.DataFrame.rollup

DataFrame.rollup(*cols: ColumnOrName) → GroupedData

Create a multi-dimensional rollup for the current DataFrame using the specified columns, so we can run aggregation on them.

Examples

>>> df.rollup("name", df.age).count().orderBy("name", "age").show()
+-----+----+-----+
| name| age|count|
+-----+----+-----+
| null|null|    2|
|Alice|null|    1|
|Alice|   2|    1|
|  Bob|null|    1|
|  Bob|   5|    1|
+-----+----+-----+