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.

New in version 3.5.0.

Parameters
formatColumn or str

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

>>> 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|
+---------------+