-
Notifications
You must be signed in to change notification settings - Fork 0
/
A.Ques3.py
425 lines (255 loc) · 8.09 KB
/
A.Ques3.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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
#!/usr/bin/env python
# coding: utf-8
# In[1]:
#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[2]:
import pandas as pd
# In[3]:
originaldata = pd.read_csv("tmdb_5000_movies.csv")
originaldata.head(5)
# In[4]:
# 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[5]:
# Now I am going to answer the last question:
# 3. What influence does release date have on revenue ?
# To deal with this question. I have created a new data(choosing only two related features to this question: release_date
# and revenue), the others feature havwe been deleted. The data was renamed "Ques3.xlsx"
# Now I am going to load this data and do some neccessary taks on this data to answer this question.
# In[6]:
data = pd.read_excel("Ques3.xlsx")
# In[7]:
data.head()
# In[ ]:
#DESCRIBING THE DATA:I show the data above. It includes release_date of the movies and revenue information.
#Now, I am going to take the month information in release_date of each movie and put them in a new column beside revenue column.
# In[22]:
a = []
for i in range(len(data.release_date)):
b = data.release_date[i]
c = b.month
if c > 0:
a.append(int(c))
else:
a.append("none")
# In[23]:
data["month"] = a
# In[24]:
data.head()
# In[25]:
print(data.month.value_counts())
# In[26]:
# Now I am going to select the revenue of each month.
# In[38]:
month1 = []
month2 = []
month3 = []
month4 = []
month5 = []
month6 = []
month7 = []
month8 = []
month9 = []
month10 = []
month11 = []
month12 = []
for i in range(len(data.month)):
if data.month[i] == 1:
if data.revenue[i] != 0:
month1.append(data.revenue[i])
else:
pass
else:
pass
for i in range(len(data.month)):
if data.month[i] == 2:
if data.revenue[i] != 0:
month2.append(data.revenue[i])
else:
pass
else:
pass
for i in range(len(data.month)):
if data.month[i] == 3:
if data.revenue[i] != 0:
month3.append(data.revenue[i])
else:
pass
else:
pass
for i in range(len(data.month)):
if data.month[i] == 4:
if data.revenue[i] != 0:
month4.append(data.revenue[i])
else:
pass
else:
pass
for i in range(len(data.month)):
if data.month[i] == 5:
if data.revenue[i] != 0:
month5.append(data.revenue[i])
else:
pass
else:
pass
for i in range(len(data.month)):
if data.month[i] == 6:
if data.revenue[i] != 0:
month6.append(data.revenue[i])
else:
pass
else:
pass
for i in range(len(data.month)):
if data.month[i] == 7:
if data.revenue[i] != 0:
month7.append(data.revenue[i])
else:
pass
else:
pass
for i in range(len(data.month)):
if data.month[i] == 8:
if data.revenue[i] != 0:
month8.append(data.revenue[i])
else:
pass
else:
pass
for i in range(len(data.month)):
if data.month[i] == 9:
if data.revenue[i] != 0:
month9.append(data.revenue[i])
else:
pass
else:
pass
for i in range(len(data.month)):
if data.month[i] == 10:
if data.revenue[i] != 0:
month10.append(data.revenue[i])
else:
pass
else:
pass
for i in range(len(data.month)):
if data.month[i] == 11:
if data.revenue[i] != 0:
month11.append(data.revenue[i])
else:
pass
else:
pass
for i in range(len(data.month)):
if data.month[i] == 12:
if data.revenue[i] != 0:
month12.append(data.revenue[i])
else:
pass
else:
pass
# In[39]:
print(len(month1))
print(len(month2))
print(len(month3))
print(len(month4))
print(len(month5))
print(len(month6))
print(len(month7))
print(len(month8))
print(len(month9))
print(len(month10))
print(len(month11))
print(len(month12))
# In[36]:
# At this time, we can see that 12 months also have enough revenue information to be taken as sample on hypothesis testing.
# So, I am going to use all 12 months to answer this third question. But now, I need to choose randomly 200 revenue value
# for each month as samples.
# In[52]:
import random
# In[53]:
month1data = random.choices(month1, k=200)
month2data = random.choices(month2, k=200)
month3data = random.choices(month3, k=200)
month4data = random.choices(month4, k=200)
month5data = random.choices(month5, k=200)
month6data = random.choices(month6, k=200)
month7data = random.choices(month7, k=200)
month8data = random.choices(month8, k=200)
month9data = random.choices(month9, k=200)
month10data = random.choices(month10, k=200)
month11data = random.choices(month11, k=200)
month12data = random.choices(month12, k=200)
# In[55]:
#VISUALIZATION: Now I am going to plot these data.
# In[56]:
import matplotlib.pyplot as plt
# In[57]:
plt.plot(month1data)
# In[58]:
plt.plot(month2data)
# In[59]:
plt.plot(month3data)
# In[60]:
plt.plot(month4data)
# In[61]:
plt.plot(month5data)
# In[62]:
plt.plot(month6data)
# In[63]:
plt.plot(month7data)
# In[64]:
plt.plot(month8data)
# In[65]:
plt.plot(month9data)
# In[66]:
plt.plot(month10data)
# In[67]:
plt.plot(month11data)
# In[68]:
plt.plot(month12data)
# In[69]:
# Based on their figure, we can see that each month has the diffrence on revenue value. To find out which genres has the
# biggest average revenue value. Now I am going to calculate the average revenue for each month.
# In[70]:
def average(lst):
return sum(lst)/len(lst)
# In[71]:
print("Average revenue of month1",average(month1data))
print("Average revenue of month2",average(month2data))
print("Average revenue of month3",average(month3data))
print("Average revenue of month4",average(month4data))
print("Average revenue of month5",average(month5data))
print("Average revenue of month6",average(month6data))
print("Average revenue of month7",average(month7data))
print("Average revenue of month8",average(month8data))
print("Average revenue of month9",average(month9data))
print("Average revenue of month10",average(month10data))
print("Average revenue of month11",average(month11data))
print("Average revenue of month12",average(month12data))
# In[72]:
# After calculated the revenue value for each month, we can easily see the movies that was released at June will have the
# biggest revenue. In the other sight, all the movies have been resealed at the begining of Summer(May, June, July).
# In[73]:
# ANALYSIS: We have to two hyphothesises:
# H0: All the movies was released at the difference months that have the same revenue.
# H1: All the movies was released at the difference months that have the difference revenue.
# And I am going to apply ANOVA-oneway to test these hyphothesises.
# In[74]:
from scipy.stats import f_oneway
# In[76]:
# We can get F(theory) = 1.79 by using FINV(0.05,11,2388) formular in excel with k = 12, n = 200 and p = 0.05
# Next, we are going to find F(statistics) by apply one-way ANOVA on month1data, month2data, month3data, month4data, month5data,
# month6data, month7data, month8data, month9data, month10data, month11data, month12data.
# In[77]:
f_oneway(month1data, month2data, month3data, month4data, month5data,month6data, month7data, month8data, month9data, month10data, month11data, month12data)
# In[78]:
#CONCLUSION: So, we can see that F(theory) = 1.79 < F(statistics) = 20.93 with pvalue = 4.53x10^(-41),
# We are going to reject H0 and accept H1.
# We can make the conclusion that "All the movies was released at the difference months that have the difference revenue."
# has the most influence on revenue.
# In[ ]: