PySpark When item in list

前端 未结 1 1408
灰色年华
灰色年华 2021-01-23 01:49

Following is the action I\'m trying to achieve:

types = [\"200\",\"300\"]
def Count(ID):
    cnd = F.when((**F.col(\"type\") in types**), 1).otherwise(F.lit(0))
         


        
1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-23 02:42

    I'm not sure about what you are trying to achieve but here is the correct syntax :

    types = ["200","300"]
    from pyspark.sql import functions as F
    
    cnd = F.when(F.col("type").isin(types),F.lit(1)).otherwise(F.lit(0))
    sum_on_cnd = F.sum(cnd).alias("count_types")
    # Column
    

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