pyspark.sql.GroupedData.max#
- GroupedData.max(*cols)[source]#
Computes the max value for each numeric columns for each group.
New in version 1.3.0.
Changed in version 3.4.0: Supports Spark Connect.
Examples
>>> df = spark.createDataFrame([ ... (2, "Alice", 80), (3, "Alice", 100), ... (5, "Bob", 120), (10, "Bob", 140)], ["age", "name", "height"]) >>> df.show() +---+-----+------+ |age| name|height| +---+-----+------+ | 2|Alice| 80| | 3|Alice| 100| | 5| Bob| 120| | 10| Bob| 140| +---+-----+------+
Group-by name, and calculate the max of the age in each group.
>>> df.groupBy("name").max("age").sort("name").show() +-----+--------+ | name|max(age)| +-----+--------+ |Alice| 3| | Bob| 10| +-----+--------+
Calculate the max of the age and height in all data.
>>> df.groupBy().max("age", "height").show() +--------+-----------+ |max(age)|max(height)| +--------+-----------+ | 10| 140| +--------+-----------+