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()
Asked
Active
Viewed 477 times
0

halfer
- 19,824
- 17
- 99
- 186

maddy ghumare
- 9
- 1
-
You need to subclass MRJob: `class MRFindStdev(MRJob):` – zan Mar 03 '19 at 22:43
-
can you please tell me how? – maddy ghumare Mar 04 '19 at 02:17
-
Put MRJob in () when you define the class as per my previous comment. That tells Python to use the class MRJob as a template when MRFindStdev is created. – zan Mar 04 '19 at 08:29
-
thank you so much for your help – maddy ghumare Mar 04 '19 at 20:20
-
Can you put the data input and the output as well? – user2064809 May 02 '21 at 09:53
2 Answers
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()

Shubham Jadhav
- 11
- 2
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