gpt4 book ai didi

apache-spark - 使用并行化创建键/值对 RDD?

转载 作者:行者123 更新时间:2023-12-01 10:39:26 25 4
gpt4 key购买 nike

Spark API docs为使用并行化创建 RDD 提供以下定义:

parallelize(c, numSlices=None)

Distribute a local Python collection to form an RDD. Using xrange is recommended if the input represents a range for performance.

>>> sc.parallelize([0, 2, 3, 4, 6], 5).glom().collect()
[[0], [2], [3], [4], [6]]
>>> sc.parallelize(xrange(0, 6, 2), 5).glom().collect()
[[], [0], [], [2], [4]]

我想创建一个键/值对 RDD,如何使用并行化来实现?示例输出 RDD:

key    |  value
-------+-------
panda | 0
pink | 3
pirate | 3
panda | 1
pink | 4

最佳答案

sc.parallelize([("panda", 0), ("pink", 3)])

关于apache-spark - 使用并行化创建键/值对 RDD?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31441693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com