根据列表的匹配值过滤DataFrame中的行

时间:2020-05-13 20:54:02

标签: apache-spark pyspark

我正在使用过滤器过滤Spark DataFrame:

var notFollowingList=List(9.8,7,6,3,1)
df.filter(col("uid”).isin(notFollowingList))

但我收到一条错误消息:

Unsupported literal type classscala.collection.immutable.$colon$colon 
Can anyone help me in resolving the error?

2 个答案:

答案 0 :(得分:0)

您可以尝试以下代码段:

var notFollowingList=List(9.8,7,6,3,1)
df.filter(col("uid").isin(notFollowingList:_*))

答案 1 :(得分:0)

检查以下代码以供参考,

var notFollowingList=List(9.8,7,6,3,1)

val df = Seq(1.0,2.0,3.0,4.0,7.0).toDF("uid")
df.show()
+---+
|uid|
+---+
|1.0|
|2.0|
|3.0|
|4.0|
|7.0|
+---+
val filt_df = df.filter(col("uid").isin(notFollowingList:_*))
filt_df.show()
+---+
|uid|
+---+
|1.0|
|3.0|
|7.0|
+---+