-
Notifications
You must be signed in to change notification settings - Fork 0
/
A.Ques1.py
306 lines (149 loc) · 4.86 KB
/
A.Ques1.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#!/usr/bin/env python
# coding: utf-8
# In[68]:
#INTRODUCTION: In analytic report project, I got the data of almost 5000 movies and there are three question I need to answer.
# 1. What areas(region of the movie) has the most influence on revenue ?
# 2. How is the movie's revenue and averege score affected by its genre ?
# 3. What influence does release date have on revenue ?
# In[137]:
import pandas as pd
# In[138]:
originaldata = pd.read_csv("tmdb_5000_movies.csv")
originaldata.head(5)
# In[141]:
# Above is a original data with many features which describes for each movies. For example: butget, genres, production_counties,
# revenue, id, original_tittle, etc.
# In[142]:
# Now I am going to answer the first question:
# 1. What areas(region of the movie) has the most influence on revenue ?
# To deal with this question. I have created a new data(choosing only two related features to this question), the others
# feature havwe been deleted. The data was renamed "areas.xlsx"
# Now I am going to load this data and do some neccessary taks on this data to answer this question.
# In[143]:
data = pd.read_excel("areas.xlsx")
# In[144]:
data.head()
# In[ ]:
#DESCRIBING THE DATA:I show the data above. It includes production_countries and revenue information.
# In[151]:
data['areas'] = data.production_countries.apply(lambda x: x[17:19])
# In[152]:
data.head(10)
# In[182]:
print(data.areas.value_counts())
# In[ ]:
# There are many areas where the movies was made. In this data we have 71 countries. But there are many contries only have a few
# movies so I will only choose several countries that have over 170 movies in this data. There are 5 of them: US, GB, CA, DE, FR
# I will take all the revenue of these countries's movies into 5 lists.
# In[248]:
regionUS = []
regionGB = []
regionCA = []
regionDE = []
regionFR = []
# In[249]:
for i in range(len(data.areas)):
if data.areas[i] == "US":
if data.revenue[i] != 0:
regionUS.append(data.revenue[i])
else:
pass
else:
pass
# In[250]:
for i in range(len(data.areas)):
if data.areas[i] == "GB":
if data.revenue[i] != 0:
regionGB.append(data.revenue[i])
else:
pass
else:
pass
# In[251]:
for i in range(len(data.areas)):
if data.areas[i] == "CA":
if data.revenue[i] != 0:
regionCA.append(data.revenue[i])
else:
pass
else:
pass
# In[252]:
for i in range(len(data.areas)):
if data.areas[i] == "DE":
if data.revenue[i] != 0:
regionDE.append(data.revenue[i])
else:
pass
else:
pass
# In[253]:
for i in range(len(data.areas)):
if data.areas[i] == "FR":
if data.revenue[i] != 0:
regionFR.append(data.revenue[i])
else:
pass
else:
pass
# In[254]:
print(len(regionUS))
print(len(regionGB))
print(len(regionCA))
print(len(regionDE))
print(len(regionFR))
# In[191]:
# Now I am going to choose 150 sample of each areas above randomly.
# In[192]:
import random
# In[265]:
dataUS = random.choices(regionUS, k=100)
dataGB = random.choices(regionGB, k=100)
dataCA = random.choices(regionCA, k=100)
dataDE = random.choices(regionDE, k=100)
dataFR = random.choices(regionFR, k=100)
# In[266]:
#VISUALIZATION: Now I am going to plot these data.
# In[267]:
import matplotlib.pyplot as plt
# In[268]:
plt.plot(dataUS)
# In[269]:
plt.plot(dataGB)
# In[270]:
plt.plot(dataCA)
# In[271]:
plt.plot(dataDE)
# In[272]:
plt.plot(dataFR)
# In[273]:
def average(lst):
return sum(lst)/len(lst)
# In[274]:
print("Average revenue of US",average(dataUS))
print("Average revenue of GB",average(dataGB))
print("Average revenue of CA",average(dataCA))
print("Average revenue of DE",average(dataDE))
print("Average revenue of FR",average(dataFR))
# In[275]:
# We can see that GB has the biggest revenues on these sample.
# In[276]:
# We can see that each areas has difference revenue.
# In[277]:
#ANALYSIS: We have to two hyphothesises:
# H0: All the areas have the same revenue
# H1: These araes have differense revenue
# And I am going to apply ANOVA-oneway to test these hyphothesises.
# In[278]:
from scipy.stats import f_oneway
# In[282]:
#We can get F(theory) = 2.38 by using FINV(0.05,4,746) formular in excel with k = 5, n = 150 and p = 0.05
# Next, we are going to find F(statistics) by apply one-way ANOVA on dataUS, dataGB, dataCA, dataDE and dataFR
# In[283]:
f_oneway(dataUS,dataGB,dataCA,dataDE,dataFR)
# In[284]:
#CONCLUSION: So, we can see that F(theory) = 2.38 < F(statistics) = 3.77 with pvalue = 0.00488,
# We are going to reject H0 and accept H1.
# We can make the conclusion that "These araes have differense revenue" and "GB(United Kingdom)"
# has the most influence on revenue.
# In[ ]: