Pyspark:根据两列中的空值过滤数据帧



我有一个类似的数据帧

id    customer_name     city       order
1     John              dallas      5
2     steve                         4
3                       austin      3
4     Ryan              houston     2
5                                   6
6     nyle              austin      4 

我想过滤掉customer_name和city都为null的行。如果其中一个具有值,则不应对其进行筛选。结果应为

id    customer_name     city       order
1     John              dallas      5
2     steve                         4
3                       austin      3
4     Ryan              houston     2
6     nyle              austin      4 

我只能根据一列找到筛选条件。如何基于两列进行筛选?

使用coalesce

from pyspark.sql.functions import *
df.filter(coalesce('customer_name', 'city').isNotNull())

我相信这将通过使用这些和f别名来实现。

df.filter(f.col("customer_name").isNotNull() & f.col("city").isNotNull())

最新更新