pyspark.sql.functions.repeat#
- pyspark.sql.functions.repeat(col, n)[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
- Returns
Column
string with repeated values.
Examples
>>> import pyspark.sql.functions as sf >>> spark.createDataFrame( ... [('ab',)], ['s',] ... ).select(sf.repeat("s", 3)).show() +------------+ |repeat(s, 3)| +------------+ | ababab| +------------+
>>> import pyspark.sql.functions as sf >>> spark.createDataFrame( ... [('ab',)], ['s',] ... ).select(sf.repeat("s", sf.lit(4))).show() +------------+ |repeat(s, 4)| +------------+ | abababab| +------------+
>>> import pyspark.sql.functions as sf >>> spark.createDataFrame( ... [('ab', 5,)], ['s', 't'] ... ).select(sf.repeat("s", 't')).show() +------------+ |repeat(s, t)| +------------+ | ababababab| +------------+