【发布时间】:2021-11-20 03:00:49
【问题描述】:
我在一个数据框中有一个 col,它是一个结构数组。我想过滤掉一些带有所有空值的结构。例如使用以下数据框:
+—————+————————————————---------------------—+
|advertiser |brands |
+—————+—————————————---------------------————+
Advertiser1 [{"id" : "a", "type" : "b", "name" : "c"}]
Advertiser2 [{"id" : null, "type" : null, "name" : null}]
+—————+————————————---------------------—————+
我想过滤掉具有空值的结构以获得:
+—————+———————————————---------------------——+
|advertiser |brands |
+—————+————————————---------------------—————+
Advertiser1 [{"id" : "a", "type" : "b", "name" : "c"}]
Advertiser2 []
+—————+—————————————---------------------————+
如果我能想出一个空值结构,我想这就是这样的事情:
.withColumn(
"brands",
when(
col("brands").equalTo(*emptyStruct?*),
null
)
)
【问题讨论】:
标签: scala dataframe pyspark apache-spark-sql