pyspark.sql.functions.concat_ws#

pyspark.sql.functions.concat_ws(sep, *cols)[source]#

Concatenates multiple input string columns together into a single string column, using the given separator.

Added in version 1.5.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters:
sepliteral string

words separator. A column that evaluates to a string.

colsColumn or column name

list of columns to work on. Each a column that evaluates to a string or an array of strings.

Returns:
Column

string of concatenated words. Returns a column that evaluates to a string.

Examples

>>> from pyspark.sql import functions as sf
>>> df = spark.createDataFrame([("abcd", "123")], ["s", "d"])
>>> df.select("*", sf.concat_ws("-", df.s, "d", sf.lit("xyz"))).show()
+----+---+-----------------------+
|   s|  d|concat_ws(-, s, d, xyz)|
+----+---+-----------------------+
|abcd|123|           abcd-123-xyz|
+----+---+-----------------------+