In [7]:
%matplotlib inline
import pandas as pd

In [8]:
from IPython.core.display import HTML
css = open('style-table.css').read() + open('style-notebook.css').read()
HTML('<style>{}</style>'.format(css))


Out[8]:

In [9]:
titles = pd.DataFrame.from_csv('data/titles.csv', index_col=None)
titles.head()


Out[9]:
title year
0 Night Walker 2017
1 Black Devil Doll 2007
2 Sedmaya pulya 1973
3 The Gentleman from Louisiana 1936
4 Agente XU 777 1963

In [10]:
cast = pd.DataFrame.from_csv('data/cast.csv', index_col=None)
cast.head()


Out[10]:
title year name type character n
0 Suuri illusioni 1985 Homo $ actor Guests 22
1 Gangsta Rap: The Glockumentary 2007 Too $hort actor Himself NaN
2 Menace II Society 1993 Too $hort actor Lew-Loc 27
3 Porndogs: The Adventures of Sadie 2009 Too $hort actor Bosco 3
4 Stop Pepper Palmer 2014 Too $hort actor Himself NaN

How many movies are listed in the titles dataframe?


In [13]:
titles.tail()


Out[13]:
title year
212806 Laura Cadieux... la suite 1999
212807 His Tiger Wife 1928
212808 Ivan Megharoopan 2012
212809 Slam Dunk: Zenkoku Seiha da! Sakuragi Hanamichi 1994
212810 Bad Lieutenant 1992

In [14]:
len(titles)


Out[14]:
212811

What are the earliest two films listed in the titles dataframe?


In [35]:
titles.sort(columns='year', ascending=True).head()[:2]


Out[35]:
title year
75090 Miss Jerry 1894
208146 Reproduction of the Corbett and Fitzsimmons Fight 1897

In [ ]:

How many movies have the title "Hamlet"?


In [57]:
titles[titles['title'].str.contains('Hamlet')].sort('year')


Out[57]:
title year
167186 Hamlet 1910
110718 Hamlet 1911
146662 Hamlet 1913
136937 A Sagebrush Hamlet 1919
173152 Hamlet 1921
87192 Han, hun og Hamlet 1922
134945 Han, hun og Hamlet 1932
27537 Hamlet 1948
1280 Hamlet 1954
172705 Hamlet (II) 1964
77186 Hamlet 1964
143062 Hamlet 1969
124666 Hamlet 1973
205860 Predstava 'Hamleta' u Mrdusi Donjoj 1974
203660 Hamlet 1976
62375 Kadin Hamlet 1977
38689 Hamlet 1987
94444 Hamlet liikemaailmassa 1987
3263 Hamlet: Prince of Denmark 1989
122294 Hamlet 1990
66740 H for Hamlet 1993
144387 Green Eggs and Hamlet 1995
180973 Fuck Hamlet 1996
47778 Hamlet 1996
95072 Hamlet, Prince of Denmark 1997
159308 Hamlet 2000
38080 Hamlet in the Hamptons 2002
198307 Hamlet_X 2003
210019 Hamlet X 2004
182638 Dogg's Hamlet, Cahoot's Macbeth 2005
119773 Hamlet (II) 2005
27436 The Tragedy of Hamlet Prince of Denmark 2007
17995 Hamlet (III) 2007
186622 Hamlet (II) 2007
75281 Hamlet 2 2008
133220 Hamlet the Vampire Slayer 2008
105551 Kitchen Hamlet 2009
188073 Hamlet 2009
182527 Hamlet 2011
34283 Hamlet Unbound 2012
124660 Zombie Hamlet 2012
48552 Harry, Hamlet and I 2013
76061 Hamlet A.D.D. 2014
193231 Hamlet 2014
158953 Hamlet's Ghost 2014
174405 Hamlet (III) 2015
44725 Hamlet 2015
7032 National Theatre Live: Hamlet 2015
44187 Hamlet (II) 2015
209484 Hamlet, Son of a Kingpin 2015
106391 Hamlet (A Modern Adaptation) 2016
120226 Hamlet 2016
133518 Hamlet: The Fall of a Sparrow 2016

In [ ]:

How many movies are titled "North by Northwest"?


In [45]:
len(titles[titles.title == 'North by Northwest'])


Out[45]:
1

In [ ]:

When was the first movie titled "Hamlet" made?


In [49]:
titles[titles['title'] 'Hamlet'].sort('year')[:1]


Out[49]:
title year
167186 Hamlet 1910

In [ ]:

List all of the "Treasure Island" movies from earliest to most recent.


In [53]:
titles[titles.title == 'Treasure Island'].sort('year')


Out[53]:
title year
78006 Treasure Island 1918
41697 Treasure Island 1920
188475 Treasure Island 1934
38126 Treasure Island 1950
16087 Treasure Island 1972
164157 Treasure Island 1973
171892 Treasure Island 1985
68316 Treasure Island 1999

In [ ]:

How many movies were made in the year 1950?


In [54]:
len(titles[titles.year == 1950])


Out[54]:
1033

In [ ]:

How many movies were made in the year 1960?


In [55]:
movies_of_1960 = titles[titles.year == 1960]
len(movies_of_1960)


Out[55]:
1423

In [ ]:

How many movies were made from 1950 through 1959?


In [67]:
moviesOf1950And1959 = titles[(titles.year >= 1950) & (titles.year <= 1950)]
len(moviesOf1950And1959)


Out[67]:
1033

In [ ]:

In what years has a movie titled "Batman" been released?


In [ ]:


In [ ]:

How many roles were there in the movie "Inception"?


In [ ]:


In [ ]:

How many roles in the movie "Inception" are NOT ranked by an "n" value?


In [ ]:


In [ ]:

But how many roles in the movie "Inception" did receive an "n" value?


In [ ]:


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 [ ]:


In [ ]:

Display the entire cast, in "n"-order, of the 1972 film "Sleuth".


In [ ]:


In [ ]:

Now display the entire cast, in "n"-order, of the 2007 version of "Sleuth".


In [ ]:


In [ ]:

How many roles were credited in the silent 1921 version of Hamlet?


In [ ]:


In [ ]:

How many roles were credited in Branagh’s 1996 Hamlet?


In [ ]:


In [ ]:

How many "Hamlet" roles have been listed in all film credits through history?


In [ ]:


In [ ]:

How many people have played an "Ophelia"?


In [ ]:


In [ ]:

How many people have played a role called "The Dude"?


In [ ]:


In [ ]:

How many people have played a role called "The Stranger"?


In [ ]:


In [ ]:

How many roles has Sidney Poitier played throughout his career?


In [ ]:


In [ ]:

How many roles has Judi Dench played?


In [ ]:


In [ ]:

List the supporting roles (having n=2) played by Cary Grant in the 1940s, in order by year.


In [ ]:


In [ ]:

List the leading roles that Cary Grant played in the 1940s in order by year.


In [ ]:


In [ ]:

How many roles were available for actors in the 1950s?


In [ ]:


In [ ]:

How many roles were avilable for actresses in the 1950s?


In [ ]:


In [ ]:

How many leading roles (n=1) were available from the beginning of film history through 1980?


In [ ]:


In [ ]:

How many non-leading roles were available through from the beginning of film history through 1980?


In [ ]:


In [ ]:

How many roles through 1980 were minor enough that they did not warrant a numeric "n" rank?


In [ ]:


In [82]:
titles.year.value_counts().sort_index().plot()


Out[82]:
<matplotlib.axes._subplots.AxesSubplot at 0x10fc49940>

In [ ]: