from mrjob.job import MRJob class Job(MRJob): def mapper(self, key, value): words = value.strip().split(',') full_name = words[-3] + ' ' + words[-2] price, qty = float(words[-5]), int(words[-4]) price...


from mrjob.job import MRJob





class Job(MRJob):


def mapper(self, key, value):


words = value.strip().split(',')


full_name = words[-3] + ' ' + words[-2]


price, qty = float(words[-5]), int(words[-4])


price = price * qty


yield full_name, (price, qty)






def combiner(self, key, values):


totalprice, totalqty = 0,0


for value in values:


totalprice += (value[0])


totalqty += value[1]


yield key, (totalprice, totalqty)






def reducer(self, key, values):


totalprice, totalqty = 0,0


for value in values:


totalprice += (value[0])


totalqty += value[1]


average = round(totalprice/totalqty,2)


yield key, average



if __name__ == '__main__':


Job.run()


Aug 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here