【问题标题】:Split row of tuple to two row in RDD将元组行拆分为 RDD 中的两行
【发布时间】:2022-01-10 21:52:15
【问题描述】:

我尝试将整数元组拆分为 RDD 中的两行。

vertices=edges.map(lambda x:(x[0],)).union(edges.map(lambda x:(x[1],))).distinct()

我尝试了这段代码,它正在运行,但我想要在运行时运行较少的代码,而不使用 GraphFrames 包。

【问题讨论】:

    标签: pyspark rdd


    【解决方案1】:

    你可以使用flatMap:

    edges.flatMap(lambda x: x).distinct()
    

    在 Scala 中,您只需调用 .flatMap(identity)。

    如果您使用DataFrame API,您可以只在您唯一的列上使用explode,例如df.select(explode("edge"))

    【讨论】:

      猜你喜欢
      • 2016-04-11
      • 1970-01-01
      • 2019-09-19
      • 2018-10-20
      • 2020-12-06
      • 2016-01-03
      相关资源
      最近更新 更多