如何在pyspark中过滤数组列中的值?

ldioqlga  于 2021-05-17  发布在  Spark
关注(0)|答案(1)|浏览(394)

我在pyspark中有一列arraytype。我只想过滤数组中每一行的值(我不想过滤掉实际的行!)不使用自定义项。
例如,给定列a为arraytype的数据集:

|     A      |
______________
|[-2, 1, 7]  |
|[1]         |
|[-4, -1, -3]|

我只想得到正值,输出值是:

|     A      |
______________
|[1, 7]      |
|[1]         |
|[]          |
gcuhipw9

gcuhipw91#

对于spark 2.4及更高版本,

from pyspark.sql.functions import expr

df.withColumn("A", expr("filter(A, x -> x > 0)")).show()

相关问题