-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_Solution of Exercise1.py
422 lines (130 loc) · 4.76 KB
/
_Solution of Exercise1.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
#!/usr/bin/env python
# coding: utf-8
# In[72]:
get_ipython().run_line_magic('matplotlib', 'inline')
import pandas as pd
import numpy as np
# In[120]:
cast = pd.read_csv("E:/Python docs/cast.csv")
cast.head()
# ### How many movies are listed in the titles dataframe?
# In[85]:
df=pd.DataFrame['title'].count()
print(df)
# In[35]:
print(data.shape)
# ### What are the earliest two films listed in the titles dataframe?
# In[132]:
cast.sort_values(by='year').head(2)
# ### How many movies have the title "Hamlet"?
# In[105]:
len(np.where(pd.DataFrame['title'] == 'Hamlet')[0])
# ### How many movies are titled "North by Northwest"?
# In[134]:
len(cast[cast.title=="North by Northwest"])
# ### When was the first movie titled "Hamlet" made?
# In[137]:
cast[cast.title=="Hamlet"].year.min()
# ### List all of the "Treasure Island" movies from earliest to most recent.
# In[138]:
cast[cast.title=="Treasure Island"].sort_values(by='year')
# ### How many movies were made in the year 1950?
# In[141]:
len(cast[cast.year==1950])
# In[ ]:
# ### How many movies were made in the year 1960?
# In[142]:
len(cast[cast.year==1960])
# In[ ]:
# ### How many movies were made from 1950 through 1959?
# In[144]:
len(cast[(cast.year>=1950) & (cast.year<=1959)])
# In[ ]:
# ### In what years has a movie titled "Batman" been released?
# In[148]:
cast[cast.title=="Batman"].sort_values(by='year')
# In[ ]:
# ### How many roles were there in the movie "Inception"?
# In[150]:
len(cast[cast.title=="Inception"])
# In[ ]:
# ### How many roles in the movie "Inception" are NOT ranked by an "n" value?
# In[152]:
len(cast[(cast.title=="Inception")&(cast.n.isnull())])
# In[ ]:
# ### But how many roles in the movie "Inception" did receive an "n" value?
# In[153]:
len(cast[(cast.title=="Inception")&(cast.n.notnull())])
# In[ ]:
# ### Display the cast of "North by Northwest" in their correct "n"-value order, ignoring roles that did not earn a numeric "n" value.
# In[157]:
cast[(cast.title=="North by Northwest") & (cast.n.notnull())].sort_values(by='n')
# In[ ]:
# ### Display the entire cast, in "n"-order, of the 1972 film "Sleuth".
# In[158]:
cast[(cast.title=="Sleuth") & (cast.year==1972) &(cast.n.notnull())].sort_values(by='n')
# In[ ]:
# ### Now display the entire cast, in "n"-order, of the 2007 version of "Sleuth".
# In[159]:
cast[(cast.title=="Sleuth") & (cast.year==2007) &(cast.n.notnull())].sort_values(by='n')
# In[ ]:
# ### How many roles were credited in the silent 1921 version of Hamlet?
# In[162]:
len(cast[(cast.title=="Hamlet") & (cast.year==1921)])
# In[ ]:
# ### How many roles were credited in Branagh’s 1996 Hamlet?
# In[163]:
len(cast[(cast.title=="Hamlet") & (cast.year==1996)])
# In[ ]:
# ### How many "Hamlet" roles have been listed in all film credits through history?
# In[164]:
len(cast[cast.character=='Hamlet'])
# In[ ]:
# ### How many people have played an "Ophelia"?
# In[165]:
len(cast[cast.character== "Ophelia"])
# In[ ]:
# ### How many people have played a role called "The Dude"?
# In[166]:
len(cast[cast.character== "The Dude"])
# In[ ]:
# ### How many people have played a role called "The Stranger"?
# In[167]:
len(cast[cast.character== "The Stranger"])
# In[ ]:
# ### How many roles has Sidney Poitier played throughout his career?
# In[170]:
len(cast[cast.name== "Sidney Poitier"])
# In[ ]:
# ### How many roles has Judi Dench played?
# In[173]:
len(cast[cast.name=="Judi Dench"])
# In[ ]:
# ### List the supporting roles (having n=2) played by Cary Grant in the 1940s, in order by year.
# In[176]:
cast[(cast.name =="Cary Grant")& (cast.year// 10==194)&(cast.n ==2)].sort_values(by='year')
# In[ ]:
# ### List the leading roles that Cary Grant played in the 1940s in order by year.
# In[177]:
cast[(cast.name =="Cary Grant")& (cast.year// 10==194)].sort_values(by='year')
# In[ ]:
# ### How many roles were available for actors in the 1950s?
# In[181]:
len(cast[(cast.type =="actor")& (cast.year// 10==195)])
# In[ ]:
# ### How many roles were available for actresses in the 1950s?
# In[182]:
len(cast[(cast.type =="actress")& (cast.year// 10==195)])
# In[ ]:
# ### How many leading roles (n=1) were available from the beginning of film history through 1980?
# In[183]:
len(cast[(cast.year ==1980)& (cast.n==1)])
# In[ ]:
# ### How many non-leading roles were available through from the beginning of film history through 1980?
# In[184]:
len(cast[(cast.year ==1980)& (cast.n!=1)])
# In[ ]:
# ### How many roles through 1980 were minor enough that they did not warrant a numeric "n" rank?
# In[185]:
len(cast[(cast.year <=1980)& (cast.n.isnull())])
# In[ ]: