筛选PySpark数据帧行
我有一个复杂的数据结构,我设法将其展平,输出具有以下结构:筛选PySpark数据帧行,pyspark,spark-dataframe,Pyspark,Spark Dataframe,我有一个复杂的数据结构,我设法将其展平,输出具有以下结构: 'name' ------ ['a','b','c'] [] [null] null ['f'] [null,'d'] 过滤上述数据帧后的所需输出: 'name' ------ ['a','b','c'] ['f'] 我知道只有“null”的行可以使用df.where(col('name').isNotNull())进行过滤。我试着用 filtered = udf(la
'name'
------
['a','b','c']
[]
[null]
null
['f']
[null,'d']
过滤上述数据帧后的所需输出:
'name'
------
['a','b','c']
['f']
我知道只有“null”的行可以使用df.where(col('name').isNotNull())
进行过滤。我试着用
filtered = udf(lambda row: int(not all(x is None for x in row)),IntegerType())
但这并没有产生我所希望的结果。如何筛选空列表或至少包含一个空值的行?下面的筛选函数可以用作您的自定义项
filtered = lambda x: not bool([y for y in x if y is None]) if x else False
>>> filtered(['a','b','c'])
True
>>> filtered([])
False
>>> filtered([None])
False
>>> filtered(None)
False
>>> filtered(['f'])
True
>>> filtered([None,'d'])
False
[null]你是说[None]?我的Python脚本的输出是null,而不是None。我没有看到notbool。相反,我用了布尔。现在效果很好!