array_min #
pyspark.sql.functions.array_min(col) #
version: since 2.4.0
Collection function: returns the minimum value of the array.
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_min",
F.array_min(F.col("a")))
)
df.show()
a | array_min |
---|---|
[1, 2, 2] | 1 |
[3, null, 5] | 3 |
Usage:
Simple array function.
returns: Column(sc.\_jvm.functions.array_min(\_to_java_column(col)))
tags: smallest number in array, lowest in array, lowest in list
© 2023 PySpark Is Rad