0
我使用mrjob libaries在python中編碼mapreducer。我安裝mrjob包,但是當我from mrjob.step import MRStep
它出現錯誤:ImportError:No module named step
from mrjob.step import MRStep
ImportError: No module named step
任何人都可以幫我嗎?非常感謝
我使用mrjob libaries在python中編碼mapreducer。我安裝mrjob包,但是當我from mrjob.step import MRStep
它出現錯誤:ImportError:No module named step
from mrjob.step import MRStep
ImportError: No module named step
任何人都可以幫我嗎?非常感謝
大家好,我解決了這個問題,這裏是字數的工作代碼。基本上,一個簡單的替換對我有效。
def mapper_get_words(self, _, line):
# yield each word in the line
for word in WORD_RE.findall(line):
yield (word.lower(), 1)
def combiner_count_words(self, word, counts):
# sum the words we've seen so far
yield (word, sum(counts))
def reducer_count_words(self, word, counts):
# send all (num_occurrences, word) pairs to the same reducer.
# num_occurrences is so we can easily use Python's max() function.
yield None, (sum(counts), word)
# discard the key; it is just None
def reducer_find_max_word(self, _, word_count_pairs):
# each item of word_count_pairs is (count, word),
# so yielding one results in key=counts, value=word
yield max(word_count_pairs)
def steps(self):
return [
self.mr(mapper=self.mapper_get_words,
combiner=self.combiner_count_words,
reducer=self.reducer_count_words),
self.mr(reducer=self.reducer_find_max_word)
]
:
從mrjob.job進口MRJob 進口重新WORD_RE = re.compile(R 「[\ W'] +」)
類MRMostUsedWord(MRJob)
如果名 == '主要': MRMostUsedWord.run()
概率很好,因爲mrjob.job中沒有mrjob – dnit13
裏面沒有模塊或文件import MRJob work fine,bro。 – NoobFromVN
不是。它的語法無效,@ R.Murray。我遵循教程,我看到它工作正常。不同的事情只是他們使用窗口和我使用的Ubuntu的 – NoobFromVN