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