forked from Ajinkya-Sonawane/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Map Reduce on Movies Dataset Implementation
- Loading branch information
Showing
3 changed files
with
104,841 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
Author : Ajinkya Sonawane | ||
""" | ||
import pandas as pd | ||
|
||
data = pd.read_csv('ratings_small.csv') | ||
#print(data) | ||
data = data.iloc[:1000,:] | ||
|
||
def find(movieId): | ||
global data | ||
temp = [] | ||
for index,row in data.iterrows(): | ||
if row['movieId'] == movieId: | ||
temp.append(row['rating']) | ||
return temp | ||
|
||
def process(): | ||
unique_movei_ids = set(data['movieId']) | ||
mapped_values = {} | ||
reduced_values = {} | ||
|
||
#Map the ratings with same movie id | ||
for i in list(unique_movei_ids): | ||
mapped_values[i] = find(i) | ||
|
||
#Reduce the mapped values by taking the average of the ratings | ||
for key,value in mapped_values.items(): | ||
reduced_values[key] = sum(value)/len(value) | ||
print(key,':',mapped_values[key],'-->',reduced_values[key]) | ||
|
||
process() |
Oops, something went wrong.