check if a row value is null in spark dataframe

前端 未结 1 994
栀梦
栀梦 2021-01-07 07:14

I am using a custom function in pyspark to check a condition for each row in a spark dataframe and add columns if condition is true.

The code is as below:

         


        
1条回答
  •  自闭症患者
    2021-01-07 08:08

    Considering that sdf is a DataFrame you can use a select statement.

    sdf.select("*", when(col("pro").isNull(), lit("new pro")).otherwise(col("pro")))
    

    0 讨论(0)
提交回复
热议问题