How do I use multiple conditions with pyspark.sql.functions.when()?

前端 未结 3 1455
逝去的感伤
逝去的感伤 2020-12-14 16:22

I have a dataframe with a few columns. Now I want to derive a new column from 2 other columns:

from pyspark.sql import functions as F
new_df = df.withColumn         


        
3条回答
  •  佛祖请我去吃肉
    2020-12-14 16:56

    Use parentheses to enforce the desired operator precedence:

    F.when( (df["col-1"]>0.0) & (df["col-2"]>0.0), 1).otherwise(0)
    

提交回复
热议问题