【问题标题】:Pyspark filter with a column from a different dataframe具有来自不同数据帧的列的 Pyspark 过滤器
【发布时间】:2019-06-27 01:23:51
【问题描述】:

我想从事件数据框中存在的价格中过滤 ID。我的代码在下面,但它在 pyspark 中不起作用。我将如何解决这个问题?

events = spark.createDataFrame([(657,'Conferences'),
                          (765, 'Seminars '),
                          (776, 'Meetings'),
                          (879, 'Conferences'),
                          (765, 'Meetings'),
                          (879, 'Seminars'),
                          (985, 'Meetings'),
                          (879, 'Meetings'),
                          (657, 'Seminars'),
                          (657,'Conferences')]
                         ,['Id', 'event_name'])
events.show()
price = spark.createDataFrame([(657,10),
                          (879,45),
                          (776,54),
                          (879,45),
                          (765, 65)]
                         ,['Id','Price'])


price[price.Id.isin(events.Id)].show()

【问题讨论】:

标签: filter pyspark


【解决方案1】:

简单的连接将只获取事件表中存在的 id 的价格

events.join(price, "Id").select("Id", "Price").distinct().show()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-23
    • 2021-03-21
    • 1970-01-01
    • 2017-03-16
    • 2021-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多