array_max

array_max #

pyspark.sql.functions.array_max(col) #

version: since 2.4.0

Collection function: returns the maximum value of the array.

array_max

Runnable Code:

from pyspark.sql import functions as F
# Set up dataframe
data = [{"a":1,"b":2,"c":2},{"a":3,"c":5}]
df = spark.createDataFrame(data)
df = df.select(F.array(F.col("a"),F.col("b"),F.col("c")).alias("a"))
# Use function
df = (df
     .withColumn("array_max",
       F.array_max(F.col("a")))
     )
df.show()
a array_max
[1, 2, 2] 2
[3, null, 5] 5

Usage:

Simple array function.



returns: Column(sc.\_jvm.functions.array_max(\_to_java_column(col)))

PySpark manual

tags: largest number in array, highest in array, highest in list




© 2023 PySpark Is Rad