【发布时间】:2017-03-29 03:15:33
【问题描述】:
我正在使用 PySpark,我正在寻找一种将 RDD 随机拆分为 n 个公平部分的方法。给定:
RDD = sc.parallelize(range(50))
我的代码:
from itertools import repeat
def split_population_into_parts(rdd):
N = 4
weight_part = float(1) / float(N)
weights_list = list(repeat(weight_part, N))
repartionned_rdd = rdd.randomSplit(weights = weights_list)
#And just to check what weights give, I did :
for i in repartionned_rdd:
print len(i.collect())
split_population_into_parts(rdd = RDD)
知道 weights = [0.25, 0.25, 0.25, 0.25],我的代码可以举个例子(作为 RDD 长度):
9
19
11
11
为什么 randomSplit 在这里不尊重权重?例如,我希望以 12、12、12 和 14 作为长度,或 12、12、13 和 13。最有效的方法是什么?谢谢!
【问题讨论】:
标签: python apache-spark pyspark spark-dataframe rdd