Question: Good morning I need help modifying a program in python. by importing MRStep you have to create more than one mapper and one reducer and

Good morning I need help modifying a program in python.

by importing MRStep you have to create more than one mapper and one reducer and find out:

a) Sum of all ratings that the movie ids got

b) Max no of ratings that a specific ID got.

You are creating two different files to show the sum of all ratings that the movie ids got and the max no of ratings that an id got Hint: For max ratings use Python max() function

The code to be tweak is the following

from mrjob.job import MRJob from mrjob.step import MRStep import re

WORD_REGEXP = re.compile(r"[\w']+") class MRMovies(MRJob):

def steps(self): return [ MRStep(mapper=self.mapper_get_words, reducer=self.reducer_count_words), MRStep(mapper=self.mapper_make_counts_key, reducer = self.reducer_output_words) ]

def mapper_get_words(self, _, line): words = WORD_REGEXP.findall(line) for word in words: yield word.lower(), 1

def reducer_count_words(self, word, values): # yield word, sum(values)

def mapper_make_counts_key(self, word, count): yield '%04d'%int(count), word

def reducer_output_words(self, count, words): for word in words: yield count, word

if __name__ == '__main__': MRMovies.run()

The data file is called rating.csv and it contains 400,020 cells. However, I just put some rows as reference

userId movieId rating timestamp
1 31 2.5 1.26E+09
1 1029 3 1.26E+09
1 1061 3 1.26E+09
1 1129 2 1.26E+09
1 1172 4 1.26E+09
1 1263 2 1.26E+09
1 1287 2 1.26E+09
1 1293 2 1.26E+09
1 1339 3.5 1.26E+09
1 1343 2 1.26E+09
1 1371 2.5 1.26E+09
1 1405 1 1.26E+09
1 1953 4 1.26E+09
1 2105 4 1.26E+09
1 2150 3 1.26E+09
1 2193 2 1.26E+09
1 2294 2 1.26E+09
1 2455 2.5 1.26E+09
1 2968 1 1.26E+09
1 3671 3 1.26E+09
2 10 4 8.35E+08
2 17 5 8.35E+08
2 39 5 8.35E+08
2 47 4 8.35E+08
2 50 4 8.35E+08
2 52 3 8.35E+08

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!