通过


max (GroupedData)

计算每个组的每个数值列的最大值。

Syntax

max(*cols)

参数

参数 类型 说明
cols str 列名。 忽略非数值列。

退货

DataFrame

示例

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