0
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()
halfer
  • 19,824
  • 17
  • 99
  • 186

2 Answers2

1

try the following

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()
0

I'll turn my comment into an answer, so it can be accepted.

Subclass MRJob when creating MRFindStdev:

class MRFindStdev(MRJob):
    def mapper(self, _, line):
        # code...
zan
  • 441
  • 2
  • 8