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()
答案 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()