You need to specify a format string in the first argument, just like how you would do it in Python. The subsequent arguments would correspond to the arguments inside the format string.
import pyspark.sql.functions as F
df2 = df.withColumn("year_qtr", F.format_string('%d Quarter-%d', 'Year', 'Quarter'))
Use %s
if the columns are of string type. %d
is only suitable for int type columns.
Alternatively, you can use concat
:
import pyspark.sql.functions as F
df2 = df.withColumn("year_qtr", F.concat('Year', F.lit(' Quarter-'), 'Quarter'))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…