问题描述
我是使用 MRJob 的 MapReduce 的新手。我正在处理以下问题:
示例 当输入文件如下时;
**goat,chicken,horse
cat,horse
dog,cat,sheep
buffalo,dolphin,cat
sheeP**
The output should be:
The corresponding output will be the following:
"buffalo" ["buffalo,cat"]
"cat" ["buffalo,cat","cat,horse","dog,sheep"]
"chicken" ["goat,horse"]
"dog" ["dog,sheep"]
"dolphin" ["buffalo,cat"]
"goat" ["goat,horse"]
"horse" ["cat,"goat,horse"]
"sheep" ["dog,sheep","sheep"]
我编写了一个程序,该程序能够识别单个动物及其所在的行。但是我的代码未能将相同的动物组合到同一个列表中,如图所示。 enter image description here
这是我写的代码:
from mrjob.job import MRJob
class MRJobClassifier (MRJob):
def mapper (self,_,line):
for animal in line.split(','):
yield animal,[line]
def reducer (self,key,doc):
pass
MRJobClassifier.run()
"buffalo" ["buffalo,cat"]
"chicken" ["goat,horse"]
"cat" ["cat,horse"]
"dog" ["dog,sheep"]
"cat" ["dog,sheep"]
"dolphin" ["buffalo,cat"]
"horse" ["cat,"goat]
"goat" ["goat,horse"]
"horse" ["goat,sheep"]
"sheep" ["sheep"]
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)