Filter Pyspark dataframe column with None value

前端 未结 10 1724
小鲜肉
小鲜肉 2020-11-29 18:10

I\'m trying to filter a PySpark dataframe that has None as a row value:

df.select(\'dt_mvmt\').distinct().collect()

[Row(dt_mvmt=u\'2016-03-27\         


        
10条回答
  •  情歌与酒
    2020-11-29 18:17

    If you want to filter out records having None value in column then see below example:

    df=spark.createDataFrame([[123,"abc"],[234,"fre"],[345,None]],["a","b"])
    

    Now filter out null value records:

    df=df.filter(df.b.isNotNull())
    
    df.show()
    

    If you want to remove those records from DF then see below:

    df1=df.na.drop(subset=['b'])
    
    df1.show()
    

提交回复
热议问题