Pyspark:基于两列中的空值筛选数据帧
我有一个这样的数据帧Pyspark:基于两列中的空值筛选数据帧,pyspark,Pyspark,我有一个这样的数据帧 id customer_name city order 1 John dallas 5 2 steve 4 3 austin 3 4 Ryan houston 2 5 6 6 ny
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都为空的行。如果其中一个具有值,则不应对其进行筛选。结果应该是
id customer_name city order
1 John dallas 5
2 steve 4
3 austin 3
4 Ryan houston 2
6 nyle austin 4
我只能根据一列找到筛选条件。如何基于两列进行筛选?我相信使用这些和f alias函数可以实现这一点
df.filter(f.col("customer_name").isNotNull() & f.col("city").isNotNull())
我相信这将通过使用这些和f别名来实现
df.filter(f.col("customer_name").isNotNull() & f.col("city").isNotNull())
使用
合并
from pyspark.sql.functions import *
df.filter(coalesce('customer_name', 'city').isNotNull())
使用
合并
from pyspark.sql.functions import *
df.filter(coalesce('customer_name', 'city').isNotNull())