array_sort

array_sort #

pyspark.sql.functions.array_sort(col) #

version: since 2.4.0

Collection function: sorts the input array in ascending order. The elements of the input arraymust be orderable. Null elements will be placed at the end of the returned array.

array_sort

Runnable Code:

from pyspark.sql import functions as F
# Set up dataframe
data = [{"a":3,"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_sort",
       F.array_sort(F.col("a")))
     )
df.show()
a array_sort
[3, 2, 2] [2, 2, 3]
[3, null, 5] [3, 5, null]

Usage:

Simple array function.



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

PySpark manual

tags: sort array, sort list




© 2023 PySpark Is Rad