-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTraditional Python Codes.py
129 lines (64 loc) · 2.27 KB
/
Traditional Python Codes.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python
# coding: utf-8
# # MapReduce Assignment
# In[1]:
get_ipython().run_line_magic('cd', 'C:\\\\Users\\\\bluec\\\\desktop\\\\BDA assignment')
# ## Objective 1
# In[ ]:
# To find the relationship between high budget movies and the average ratings.
# Took 2.48 secs
# In[63]:
import pandas as pd
import numpy as np
ratings_df = pd.read_csv('ratings.csv', delimiter=',', names = ['movie_id', 'rating', 'title', 'budget'])
averages = ratings_df.groupby(['movie_id','budget']).agg({'rating':'mean'})
averages.columns = ['avgRating']
print(averages.sort_values(by=['budget'], ascending=False).head(10))
print(ratings_df.shape)
# ## Objective 2
# In[ ]:
# To identify the behaviour of the users in this dataset whether they are generous in their ratings comparing 2017 and 2019.
# Took 5.19 seconds
# In[37]:
import pandas as pd
from collections import Counter
obj1_df = pd.read_csv('obj1.csv', delimiter=',', names = ['movie_id', 'rating'])
z = obj1_df['rating']
Counter(z)
# In[38]:
import pandas as pd
from collections import Counter
obj2_df = pd.read_csv('obj2.csv', delimiter=',', names = ['movie_id', 'rating'])
z = obj2_df['rating']
Counter(z)
# ## Objective 3
# In[ ]:
# To identify the top movies rated and average ratings for each movie.
# In[2]:
import pandas as pd
import numpy as np
ratings_df = pd.read_csv('ratings.csv', delimiter=',', names = ['movie_id', 'rating', 'title', 'budget'])
averages = ratings_df.groupby(['title']).agg({'rating':'mean'})
averages.columns = ['avgRating']
print(averages.sort_values(by=['avgRating'], ascending=False).head(10))
#Takes 4.38 seconds
# In[3]:
import pandas as pd
import numpy as np
ratings_df = pd.read_csv('ratings.csv', delimiter=',', names = ['movie_id', 'rating', 'title', 'budget'])
averages = ratings_df.groupby(['title']).agg({'rating':'mean'})
averages.columns = ['avgRating']
print(averages)
#Takes 2.75 seconds
# ## Objective 4
# In[ ]:
# To find the top 10 popular movies in this dataset by the number of ratings.
# Takes 2.82 seconds
# In[4]:
import pandas as pd
from collections import Counter
ratings_df = pd.read_csv('ratings.csv', delimiter=',', names = ['movie_id', 'rating', 'title', 'budget'])
z = ratings_df['title']
y = Counter(z)
print(y.most_common(10))
# In[ ]: