我試圖開發一個mapreduce程序來顯示一個文本文件中城市的最高溫度。獲取城市和溫度值到變量文件中使用的變量
我Temperatures.txt文件有這樣的格式:
City1 10
市2月12日
...
而且我已經有mapper.py文件的工作是這樣的:
import sys
for line in sys.stdin:
line = line.strip()
print line
但是,不僅僅是做print line
,我想要做這樣的事情:
print '%s\t%s' % (city ,temperature)
由於開發reducer.py文件,我需要這個,所以我的問題是,如果你知道我怎麼能在我的mapper.py文件,得到每一行,並把我的變量城市和溫度內城市名稱我變溫裏面,像這樣:
import sys
for line in sys.stdin:
line = line.strip()
words = line.split()
for word in words:
city = # how can i get this?
temperature = # how can i get this?
print line
# so i can show the resut like this
print '%s\t%s' % (city ,temperature)
謝謝,你的解決方案工作!也感謝您的詳細解答! – UserX
@UserX,沒有問題,很高興它有幫助。 –