[英]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.