pyspark.sql.functions.format_string

pyspark.sql.functions.format_string(format: str, *cols: ColumnOrName) → pyspark.sql.column.Column

Formats the arguments in printf-style and returns the result as a string column.

Parameters
formatstr

string that can contain embedded format tags and used as result column’s value

colsColumn or str

column names or Columns to be used in formatting

Examples

>>> df = spark.createDataFrame([(5, "hello")], ['a', 'b'])
>>> df.select(format_string('%d %s', df.a, df.b).alias('v')).collect()
[Row(v='5 hello')]