array_repeat

array_repeat #

pyspark.sql.functions.array_repeat(col, count) #

version: since 2.4.0

Collection function: creates an array containing a column repeated count times.

count: int

array_repeat

Runnable Code:

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

Usage:

Simple array function.



return Column(sc.\_jvm.functions.array_repeat(\_to_java_column(col),\_to_java_column(count) if isinstance(count, Column) else count))

PySpark manual

tags: repeat as array, repeat as list




© 2023 PySpark Is Rad