Aller au contenu principal

max (GroupedData)

Calcule la valeur maximale pour chaque colonne numérique pour chaque groupe.

Syntaxe

max(*cols)

parameter

parameter

Type

Description

cols

str

Noms de colonne. Les colonnes non numériques sont ignorées.

parameter

Type

Description

cols

str

Noms de colonne. Les colonnes non numériques sont ignorées.

Renvoie

DataFrame

Exemples

Python
df = spark.createDataFrame([
(2, "Alice", 80), (3, "Alice", 100),
(5, "Bob", 120), (10, "Bob", 140)], ["age", "name", "height"])

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