-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exercises-2.py
309 lines (100 loc) · 3.8 KB
/
Exercises-2.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
#!/usr/bin/env python
# coding: utf-8
# In[2]:
get_ipython().run_line_magic('matplotlib', 'inline')
import pandas as pd
# In[17]:
titles = pd.read_csv('E:\Python docs/titles.csv')
titles.head()
# In[34]:
cast = pd.read_csv('E:\Python docs/cast.csv')
cast.head()
# In[ ]:
# ### What are the ten most common movie names of all time?
# In[20]:
titles.title.value_counts().head(10)
# In[ ]:
# ### Which three years of the 1930s saw the most films released?
# In[21]:
titles[titles.year //10 ==193].year.value_counts().head(3)
# In[ ]:
# ### Plot the number of films that have been released each decade over the history of cinema.
# In[29]:
titles['decade']=((titles.year // 10) *10)
titles.decade.value_counts().sort_index().plot(kind="bar")
# In[ ]:
# ### Plot the number of "Hamlet" films made each decade.
# In[30]:
titles['decade']=((titles.year // 10) *10)
titles[titles.title=="Hamlet"].decade.value_counts().sort_index().plot(kind="bar")
# In[ ]:
# ### Plot the number of "Rustler" characters in each decade of the history of film.
# In[37]:
cast['decade']=((cast.year // 10) *10)
cast[cast.character=="Rustler"].decade.value_counts().sort_index().plot(kind="bar")
# In[ ]:
# ### Plot the number of "Hamlet" characters each decade.
# In[38]:
cast['decade']=((cast.year // 10) *10)
cast[cast.character=="Hamlet"].decade.value_counts().sort_index().plot(kind="bar")
# In[ ]:
# ### What are the 11 most common character names in movie history?
# In[39]:
cast.character.value_counts().head(11)
# In[ ]:
# ### Who are the 10 people most often credited as "Herself" in film history?
# In[40]:
cast[cast.character=="Herself"].name.value_counts().head(10)
# In[ ]:
# ### Who are the 10 people most often credited as "Himself" in film history?
# In[41]:
cast[cast.character=="Himself"].name.value_counts().head(10)
# In[ ]:
# ### Which actors or actresses appeared in the most movies in the year 1945?
# In[42]:
cast[cast.year == 1945].name.value_counts().head(10)
# In[ ]:
# ### Which actors or actresses appeared in the most movies in the year 1985?
# In[43]:
cast[cast.year == 1985].name.value_counts().head(10)
# In[ ]:
# ### Plot how many roles Mammootty has played in each year of his career.
# In[45]:
cast[cast.character=="Mammootty"].year.value_counts().sort_index().plot(kind="bar")
# In[ ]:
# ### What are the 10 most frequent roles that start with the phrase "Patron in"?
# In[46]:
ph=cast[cast.character.str.startswith("Patron in")]
ph.character.value_counts().head(10)
# In[ ]:
# ### What are the 10 most frequent roles that start with the word "Science"?
# In[47]:
sc=cast[cast.character.str.startswith("Science")]
sc.character.value_counts().head(10)
# In[ ]:
# ### Plot the n-values of the roles that Judi Dench has played over her career.
# In[65]:
a=cast[cast.name=="Judi Dench"]
a.n.value_counts().sort_index().plot(kind="bar")
# In[55]:
x.n.value_counts()
# In[70]:
a.plot(kind="scatter",x="year",y="n", s= 0.5)
# In[ ]:
# ### Plot the n-values of Cary Grant's roles through his career.
# In[64]:
b=cast[cast.name=="Cary Grant"]
b.n.value_counts().sort_index().plot(kind="bar")
# ### Plot the n-value of the roles that Sidney Poitier has acted over the years.
# In[72]:
cast[cast.name=="Sidney Poitier"].plot(kind="scatter",x="year",y="n")
# In[73]:
cast[cast.name=="Sidney Poitier"].n.value_counts()
# ### How many leading (n=1) roles were available to actors, and how many to actresses, in the 1950s?
# In[74]:
cast[(cast.year//10==195)&(cast.n==1)].type.value_counts()
# In[ ]:
# ### How many supporting (n=2) roles were available to actors, and how many to actresses, in the 1950s?
# In[75]:
cast[(cast.year//10==195)&(cast.n==2)].type.value_counts()
# In[ ]: