【发布时间】:2016-10-27 10:07:43
【问题描述】:
我知道这是因为map 是一个函数而不是列表方法。但是有没有办法可以使用 map 函数将数据传递给内部调用的函数。
这是我的代码:
def func1(lines):
global newlst
for line in lines:
qtype = re.search("qtype=(\S+)",str(line))
......
file = sc.textFile("C:\\TestLogs\\sample.log").cache()
result = file.map(lambda x: x.split("\n")).collect()
print(type(result)) #it is a list
lines = result.map(func1).collect() #I want to pass the contents of result to func1 through map function.
错误:
lines = result.map(func1).collect()
AttributeError: 'list' object has no attribute 'map'
有没有其他方法可以将我的数据从results 传递到func1,但可以使用map 或火花中生成rdd 的任何概念?
【问题讨论】:
-
不要
.collect()
标签: apache-spark pyspark rdd