我有一个有两列的pyspark数据框。如果另一列中的行值为空,我想用固定值填充一列。因此,在customer_df中,如果customer_address为null,则将城市列填充为“未知”
我正在尝试
customer_df = customer_df.withColumn('city',when(customer_df.customer_address == '','unknown')
但这会产生语法错误。我在这里想念什么?预先感谢
答案 0 :(得分:3)
customer_df = customer_df.withColumn('city',
when(col(customer_address).isNull(), 'unknown').otherwise(col('city'))
)