在Python中使用mrjob的标准偏差显示错误“文件没有要运行的属性”

时间:2019-03-03 20:44:50

标签: python mapreduce mrjob

from mrjob.job import MRJob
import statistics
import sys

class MRFindStdev():

    def mapper(self, _, line):
        for number in line.split(','):
            yield number, float(number)

    def reducer(self, _, line):
        numbers = list(self.mapper(line))
        #total_numbers = len(numbers)
        #mean = sum(numbers)/total_numbers
        #print(numbers)
        yield statistics.stdev(numbers)


if __name__ == '__main__':
  MRFindStdev.run()

2 个答案:

答案 0 :(得分:0)

我将把我的评论变成答案,以便它可以被接受。

创建MRJob时的子类MRFindStdev

class MRFindStdev(MRJob):
    def mapper(self, _, line):
        # code...

答案 1 :(得分:0)

尝试以下

from statistics import stdev
import statistics

class deviation(MRJob):
    def mapper(self, __, line):
        for num in line.split(','):
            yield None, int(num)


    def reducer(self, __, numbr):
        yield "deviation",statistics.stdev(numbr)

if __name__ == '__main__':
    deviation.run()