-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkBook2.py
More file actions
34 lines (28 loc) · 1.01 KB
/
WorkBook2.py
File metadata and controls
34 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# second py file to perform some task on dataset
# avilable at: https://archive.ics.uci.edu/ml/datasets/Contraceptive+Method+Choice
#https://github.com/astan54321/PA3/blob/44628868dcc7f00feec9e4c4bdb9391558391ac7/problem2_3.py
from mrjob.job import MRJob
from mrjob.step import MRStep
import re
DATA_RE = re.compile(r"[\w.-]+")
class MRProb2_3(MRJob):
def steps(self):
return [
MRStep(mapper=self.mapper_get_avgWifeAge,
reducer=self.reducer_get_avg)
]
def mapper_get_avgWifeAge(self, _, line):
# yield each wifes age
# the first column is the wife's age
data = DATA_RE.findall(line)
wife_A = float(data[0])
yield ("Wife's Age", wife_A)
def reducer_get_avg(self, key, values):
# get max of the petal widths
size, total = 0, 0
for val in values:
size += 1
total += val
yield ("Wife's Average Age is: ", round(total,1) / size)
if __name__ == '__main__':
MRProb2_3.run()