【发布时间】:2019-09-26 14:43:00
【问题描述】:
我试图通过将其两列(在本例中为主题和流)与元组列表进行比较来过滤 scala 中的数据框。如果列值和元组值相等,则过滤行。
val df = Seq(
(0, "Mark", "Maths", "Science"),
(1, "Tyson", "History", "Commerce"),
(2, "Gerald", "Maths", "Science"),
(3, "Katie", "Maths", "Commerce"),
(4, "Linda", "History", "Science")).toDF("id", "name", "subject", "stream")
示例输入:
+---+------+-------+--------+
| id| name|subject| stream|
+---+------+-------+--------+
| 0| Mark| Maths| Science|
| 1| Tyson|History|Commerce|
| 2|Gerald| Maths| Science|
| 3| Katie| Maths|Commerce|
| 4| Linda|History| Science|
+---+------+-------+--------+
需要过滤上述df的元组列表
val listOfTuples = List[(String, String)] (
("Maths" , "Science"),
("History" , "Commerce")
)
预期结果:
+---+------+-------+--------+
| id| name|subject| stream|
+---+------+-------+--------+
| 0| Mark| Maths| Science|
| 1| Tyson|History|Commerce|
| 2|Gerald| Maths| Science|
+---+------+-------+--------+
【问题讨论】:
标签: scala apache-spark