【发布时间】:2022-01-10 21:52:15
【问题描述】:
我尝试将整数元组拆分为 RDD 中的两行。
vertices=edges.map(lambda x:(x[0],)).union(edges.map(lambda x:(x[1],))).distinct()
我尝试了这段代码,它正在运行,但我想要在运行时运行较少的代码,而不使用 GraphFrames 包。
【问题讨论】:
我尝试将整数元组拆分为 RDD 中的两行。
vertices=edges.map(lambda x:(x[0],)).union(edges.map(lambda x:(x[1],))).distinct()
我尝试了这段代码,它正在运行,但我想要在运行时运行较少的代码,而不使用 GraphFrames 包。
【问题讨论】:
你可以使用flatMap:
edges.flatMap(lambda x: x).distinct()
在 Scala 中,您只需调用 .flatMap(identity)。
如果您使用DataFrame API,您可以只在您唯一的列上使用explode,例如df.select(explode("edge"))
【讨论】: