check if a row value is null in spark dataframe

前端 未结 1 993
栀梦
栀梦 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)
提交回复
热议问题