pyspark.sql.DataFrame.rollup

DataFrame.rollup(*cols)[source]

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

New in version 1.4.0.

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|
+-----+----+-----+