pyspark.sql.functions.printf#

pyspark.sql.functions.printf(format, *cols)[source]#

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

Added in version 3.5.0.

Parameters:
formatColumn or str

string that can contain embedded format tags and used as result column’s value. A column that evaluates to a string.

colsColumn or str

column names or Columns to be used in formatting Each a column of any type.

Examples

>>> import pyspark.sql.functions as sf
>>> spark.createDataFrame(
...     [("aa%d%s", 123, "cc",)], ["a", "b", "c"]
... ).select(sf.printf("a", "b", "c")).show()
+---------------+
|printf(a, b, c)|
+---------------+
|        aa123cc|
+---------------+