array_remove #
pyspark.sql.functions.array_remove(col, element) #
version: since 2.4.0
Collection function: Remove all elements that equal to element from the given array.
element: string or number
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_remove",
F.array_remove(F.col("a"),2))
)
df.show()
a | array_remove |
---|---|
[1, 2, 2] | [1] |
[3, null, 5] | [3, null, 5] |
Usage:
Simple array function.
returns: Column(sc.\_jvm.functions.array_remove(\_to_java_column(col), element))
tags: delete from array, remove from array, delete from list
© 2023 PySpark Is Rad