pyspark.sql.functions.array_repeat

pyspark.sql.functions.array_repeat(col: ColumnOrName, count: Union[ColumnOrName, int]) → pyspark.sql.column.Column

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

Parameters
colColumn or str

column name or column that contains the element to be repeated

countColumn or str or int

column name, column, or int containing the number of times to repeat the first argument

Examples

>>> df = spark.createDataFrame([('ab',)], ['data'])
>>> df.select(array_repeat(df.data, 3).alias('r')).collect()
[Row(r=['ab', 'ab', 'ab'])]