简体   繁体   English

python - 如何使用map reduce MRJob

[英]python - How to use map reduce MRJob

I need to apply the map reduce function from MRJob and I can't arrive.我需要从 MRJob 应用 map reduce 功能,但我无法到达。 I have a big list with two codes and a sentence, as following:我有一个包含两个代码和一个句子的大列表,如下所示:

enter code here
    L = ['E-0053 C-0169  It's goig to be a good day\n', 'D-0312 B-0291 Peter has arrived late\n', 'A- 
    0417 B-0187  for more information please call the following number\n']

I need to use map reduce to obtain a list that counts the number of words that have each sentences for each pair of combinations of letter from the code.我需要使用 map reduce 来获取一个列表,该列表计算代码中每对字母组合的每个句子的单词数。 For example, the solution with the list example would be:例如,列表示例的解决方案是:

enter code here
    [EC 6, DB 4, AB 8]

I've tried with:我试过:

enter code here

    C1 = [i [0] for i in L]
    C2 = [i [7] for i in L]
    C1_C2 = [C1[i]+C2[i] for i in range(len(C1))] 

    class count(MRJob):
       def mapper(self, _, C1_C2):
          [elem.split() for elem in L]
          yield C1_C2, [(len(i)-2) for i in sentence]

    def reducer(self, key, values):
       yield key, sum(values)


    count.run()

You could try this :你可以试试这个:

L = [
    "E-0053 C-0169  It's goig to be a good day\n", 
    "D-0312 B-0291 Peter has arrived late\n",
    "A-0417 B-0187  for more information please call the following number\n"
]
result = [i[0] + i[7] + " " + str(len(i.split()) - 2) for i in L]
print(result)

Output :输出 :

['EC 7', 'DB 4', 'AB 8']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM