Pyspark:如果其他列为空,则在pyspark列中填充一个修复值

时间:2020-09-26 01:51:34

标签: python pyspark

我有一个有两列的pyspark数据框。如果另一列中的行值为空,我想用固定值填充一列。因此,在customer_df中,如果customer_address为null,则将城市列填充为“未知”

我正在尝试

customer_df = customer_df.withColumn('city',when(customer_df.customer_address == '','unknown')

但这会产生语法错误。我在这里想念什么?预先感谢

1 个答案:

答案 0 :(得分:3)

customer_df = customer_df.withColumn('city', 
    when(col(customer_address).isNull(), 'unknown').otherwise(col('city'))
  )