Pyspark - Sql 过滤器 - Select 通过检查数组中是否存在 id 值来过滤所有行
Pyspark - Sql filter - Select all rows by checking if the id value is presented in a array
我在 Pyspark 中有一个 DataFrame,我需要 select 行,其中 id 值显示在数组中。有谁能帮帮我吗?
示例:
+---+-----+
| id| col2|
+---+-----+
|123| 2 |
|245| 32 |
| 12| 34 |
|234| 1 |
+---+-----+
数组:[123, 12, 234]
期望结果:
+---+-----+
| id| col2|
+---+-----+
|123| 2 |
| 12| 34 |
|234| 1 |
+---+-----+
您可以将 isin
与 filter
一起使用:
ids = [123, 12, 234]
df.filter(df.id.isin(ids)).show()
+---+----+
| id|col2|
+---+----+
|123| 2|
| 12| 34|
|234| 1|
+---+----+
我在 Pyspark 中有一个 DataFrame,我需要 select 行,其中 id 值显示在数组中。有谁能帮帮我吗?
示例:
+---+-----+
| id| col2|
+---+-----+
|123| 2 |
|245| 32 |
| 12| 34 |
|234| 1 |
+---+-----+
数组:[123, 12, 234]
期望结果:
+---+-----+
| id| col2|
+---+-----+
|123| 2 |
| 12| 34 |
|234| 1 |
+---+-----+
您可以将 isin
与 filter
一起使用:
ids = [123, 12, 234]
df.filter(df.id.isin(ids)).show()
+---+----+
| id|col2|
+---+----+
|123| 2|
| 12| 34|
|234| 1|
+---+----+