pyspark dataframe filter or include based on list

后端 未结 3 814
自闭症患者
自闭症患者 2020-11-29 03:42

I am trying to filter a dataframe in pyspark using a list. I want to either filter based on the list or include only those records with a value in the list. My code below

3条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 04:30

    based on @user3133475 answer, it is also possible to call the isin() method from F.col() like this:

    import pyspark.sql.functions as F
    
    
    l = [10,18,20]
    df.filter(F.col("score").isin(l))
    

提交回复
热议问题