作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我在 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/
我是一名优秀的程序员,十分优秀!