pyspark - 如何在pyspark中查看RDD中每个分区的内容?

标签 pyspark rdd

我想更多地了解 pyspark 如何对数据进行分区。我需要一个这样的函数:

a = sc.parallelize(range(10), 5)
show_partitions(a)

#output:[[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]] (or however it partitions)

最佳答案

glom功能就是您正在寻找的:

glom(self): Return an RDD created by coalescing all elements within each partition into a list.

a = sc.parallelize(range(10), 5)
a.glom().collect()
#output:[[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]

关于pyspark - 如何在pyspark中查看RDD中每个分区的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34216390/

相关文章:

python - 语料库中的 Pyspark CountVectorizer 和词频

python - 合并从 csv 文件导入的 Dask 数据帧

python - 什么样的对象可以作为 Spark RDD 中的元素?

apache-spark - 在 spark 中将数据帧转换为 rdd 的成本

scala - Apache Spark 中的案例类相等

apache-spark - Spark : Expansion of RDD(Key, List) 到 RDD(Key, Value)

dictionary - 如何将数据集转换为存储库内的字典。我在 Foundry 中使用 pyspark

python - Spark Data Frames - 检查列是否为整数类型

python - 将 PySpark 数据帧写入 MongoDB 插入字段作为 ObjectId

dataframe - PySpark 列到其值的 RDD