pyspark.sql.functions.repeat

pyspark.sql.functions.repeat(col: ColumnOrName, n: int) → pyspark.sql.column.Column[source]

Repeats a string column n times, and returns it as a new string column.

New in version 1.5.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or str

target column to work on.

nint

number of times to repeat value.

Returns
Column

string with repeated values.

Examples

>>> df = spark.createDataFrame([('ab',)], ['s',])
>>> df.select(repeat(df.s, 3).alias('s')).collect()
[Row(s='ababab')]