gpt4 book ai didi

python - 如何在 python 中打印 rdd

转载 作者:太空狗 更新时间:2023-10-30 00:27:45 25 4
gpt4 key购买 nike

我在 HDFS 上有两个文件,我只想将这两个文件加入一个列,比如员工 ID。

我试图简单地打印文件以确保我们从 HDFS 正确读取。

lines = sc.textFile("hdfs://ip:8020/emp.txt")
print lines.count()

我也尝试了 foreach 和 println 函数,但无法显示文件数据。我在 python 中工作,对 python 和 spark 也是全新的。

最佳答案

这真的很简单,只要做一个 collect您必须确保所有数据都适合您主机上的内存

my_rdd = sc.parallelize(xrange(10000000))
print my_rdd.collect()

如果不是这种情况,您必须使用 take 取样方法。

# I use an exagerated number to remind you it is very large and won't fit the memory in your master so collect wouldn't work
my_rdd = sc.parallelize(xrange(100000000000000000))
print my_rdd.take(100)

另一个使用 .ipynb 的例子:

关于python - 如何在 python 中打印 rdd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33027949/

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