【发布时间】:2016-02-19 19:28:05
【问题描述】:
我正在 spark(单节点,独立)上运行 pyspark 作业,并尝试将输出保存在本地文件系统的文本文件中。
input = sc.textFile(inputfilepath)
words = input.flatMap(lambda x: x.split())
wordCount = words.countByValue()
wordCount.saveAsTextFile("file:///home/username/output.txt")
我收到一个错误提示
AttributeError: 'collections.defaultdict' object has no attribute 'saveAsTextFile'
基本上,无论我添加到“wordCount”对象中的什么,例如 collect() 或 map(),它都会返回相同的错误。当输出到终端时(使用 for 循环),代码可以正常工作,但我不知道将输出发送到文件时缺少什么。
【问题讨论】:
标签: python apache-spark pyspark