[英]spark- find the len of each row (python)
我写了这段代码:
logFile = sc.textFile("\README.md") #read the file
def lengthfunction(line):
return len(line)
logFile.map(lambda line: line.split()).reduce(lengthfunction)
它给了我一个错误:
"lengthfunction() takes exactly 1 argument (2 given)"
我也试过
logFile.map(lambda line: line.split()).reduce(lambda line: len)
但这也没有用。 有人可以帮我吗?
您可以:
logFile.map(lambda line: line.split()).map(len)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.