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

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


Out[3]:

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


Out[4]:
title year
0 The Rising Son 1990
1 Ashes of Kukulcan 2016
2 The Thousand Plane Raid 1969
3 Crucea de piatra 1993
4 The 86 2015

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


Out[5]:
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 [6]:
len(titles)


Out[6]:
215971

In [7]:
len(cast)


Out[7]:
3336592

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


In [8]:
orderedByYear = titles.sort('year')[:2]
orderedByYear


Out[8]:
title year
165156 Miss Jerry 1894
85703 Reproduction of the Corbett and Fitzsimmons Fight 1897

In [9]:



Out[9]:
title year

How many movies have the title "Hamlet"?


In [10]:
len(titles[titles.title == 'Hamlet'])


Out[10]:
19

In [ ]:

How many movies are titled "North by Northwest"?


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


Out[13]:
1

In [ ]:

When was the first movie titled "Hamlet" made?


In [31]:
for t in titles[titles.title == 'Hamlet'].sort('year').year[:1]:
    print(t)


1910

In [18]:



---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-18-4800b5a21aa3> in <module>()
----> 1 stuff.get(0).year

AttributeError: 'NoneType' object has no attribute 'year'

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


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


Out[34]:
title year
191385 Treasure Island 1918
47718 Treasure Island 1920
192928 Treasure Island 1934
90185 Treasure Island 1950
213041 Treasure Island 1972
103635 Treasure Island 1973
190789 Treasure Island 1985
166649 Treasure Island 1999

In [ ]:

How many movies were made in the year 1950?


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


Out[27]:
1037

In [ ]:

How many movies were made in the year 1960?


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


Out[28]:
1457

In [ ]:

How many movies were made from 1950 through 1959?


In [31]:
len(titles[(titles.year >= 1950) & (titles.year <= 1959)])


Out[31]:
12122

In [ ]:

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


In [30]:
for y in titles[titles.title == 'Batman'].year:
    print(y)


1989
1943

In [ ]:

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


In [33]:
len(cast[cast.title == 'Inception'])


Out[33]:
73

In [ ]:

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


In [68]:
len(cast[(cast.title == 'Inception') & (cast.n.isnull())])


Out[68]:
51

In [ ]:

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


In [69]:
len(cast[(cast.title == 'Inception') & ~(cast.n.isnull())])


Out[69]:
51

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 [71]:
cast[(cast.title == 'North by Northwest') & ~(cast.n.isnull())].sort('n')


Out[71]:
title year name type character n
778971 North by Northwest 1959 Cary Grant actor Roger O. Thornhill 1
3107636 North by Northwest 1959 Eva Marie Saint actress Eve Kendall 2
1301695 North by Northwest 1959 James Mason actor Phillip Vandamm 3
2796809 North by Northwest 1959 Jessie Royce Landis actress Clara Thornhill 4
317620 North by Northwest 1959 Leo G. Carroll actor The Professor 5
2704725 North by Northwest 1959 Josephine Hutchinson actress Mrs. Townsend 6
1515268 North by Northwest 1959 Philip Ober actor Lester Townsend 7
1138528 North by Northwest 1959 Martin Landau actor Leonard 8
2183294 North by Northwest 1959 Adam Williams actor Valerian 9
1618288 North by Northwest 1959 Edward Platt actor Victor Larrabee 10
594967 North by Northwest 1959 Robert Ellenstein actor Licht 11
2048118 North by Northwest 1959 Les Tremayne actor Auctioneer 12
414219 North by Northwest 1959 Philip Coolidge actor Dr. Cross 13
1348302 North by Northwest 1959 Patrick McVey actor Sergeant Flamm 14
182317 North by Northwest 1959 Edward Binns actor Captain Junket 15
1236856 North by Northwest 1959 Ken Lynch actor Charley - Chicago Policeman 16

In [ ]:

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


In [73]:
cast[(cast.title == 'Sleuth') & (cast.year == 1972) & ~(cast.n.isnull())].sort('n')


Out[73]:
title year name type character n
1524146 Sleuth 1972 Laurence Olivier actor Andrew Wyke 1
290601 Sleuth 1972 Michael Caine actor Milo Tindle 2
333128 Sleuth 1972 Alec Cawthorne actor Inspector Doppler 3
1309035 Sleuth 1972 John (II) Matthews actor Detective Sergeant Tarrant 4
2424114 Sleuth 1972 Eve (III) Channing actress Marguerite Wyke 5
1294258 Sleuth 1972 Teddy Martin actor Police Constable Higgs 6

In [ ]:

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


In [74]:
cast[(cast.title == 'Sleuth') & (cast.year == 2007) & ~(cast.n.isnull())].sort('n')


Out[74]:
title year name type character n
290602 Sleuth 2007 Michael Caine actor Andrew 1
1155121 Sleuth 2007 Jude Law actor Milo 2
1613486 Sleuth 2007 Harold Pinter actor Man on T.V. 3

In [ ]:

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


In [80]:
len(cast[(cast.title == 'Hamlet') & (cast.year == 1921)])


Out[80]:
9

In [ ]:

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


In [81]:
len(cast[(cast.title == 'Hamlet') & (cast.year == 1996)])


Out[81]:
55

In [ ]:

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


In [82]:
len(cast[(cast.title == 'Hamlet')])


Out[82]:
299

In [ ]:

How many people have played an "Ophelia"?


In [84]:
len(cast[cast.character=="Ophelia"])


Out[84]:
96

In [ ]:

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


In [85]:
len(cast[cast.character=="The Dude"])


Out[85]:
16

In [ ]:

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


In [86]:
len(cast[cast.character=="The Stranger"])


Out[86]:
192

In [ ]:

How many roles has Sidney Poitier played throughout his career?


In [88]:
len(cast[cast.name=="Sidney Poitier"])


Out[88]:
43

In [ ]:

How many roles has Judi Dench played?


In [89]:
len(cast[cast.name=="Judi Dench"])


Out[89]:
51

In [ ]:

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


In [95]:
cast[(cast.name=='Cary Grant') & (cast.n == 2) &  (cast.year >= 1940) & (cast.year < 1950)].sort('year')


Out[95]:
title year name type character n
778968 My Favorite Wife 1940 Cary Grant actor Nick 2
778978 Penny Serenade 1941 Cary Grant actor Roger Adams 2

In [ ]:

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


In [96]:
cast[(cast.name=='Cary Grant') & (cast.n == 1) &  (cast.year >= 1940) & (cast.year < 1950)].sort('year')


Out[96]:
title year name type character n
778993 The Howards of Virginia 1940 Cary Grant actor Matt Howard 1
778950 His Girl Friday 1940 Cary Grant actor Walter Burns 1
778995 The Philadelphia Story 1940 Cary Grant actor C. K. Dexter Haven 1
778983 Suspicion 1941 Cary Grant actor Johnnie 1
778997 The Talk of the Town 1942 Cary Grant actor Leopold Dilg 1
778974 Once Upon a Honeymoon 1942 Cary Grant actor Patrick 'Pat' O'Toole 1
778941 Destination Tokyo 1943 Cary Grant actor Capt. Cassidy 1
778966 Mr. Lucky 1943 Cary Grant actor Joe Adams 1
778967 Mr. Lucky 1943 Cary Grant actor Joe Bascopolous 1
778975 Once Upon a Time 1944 Cary Grant actor Jerry Flynn 1
778933 Arsenic and Old Lace 1944 Cary Grant actor Mortimer Brewster 1
778970 None But the Lonely Heart 1944 Cary Grant actor Ernie Mott 1
778969 Night and Day 1946 Cary Grant actor Cole Porter 1
778972 Notorious 1946 Cary Grant actor Devlin 1
778989 The Bachelor and the Bobby-Soxer 1947 Cary Grant actor Dick Nugent 1
778990 The Bishop's Wife 1947 Cary Grant actor Dudley 1
778965 Mr. Blandings Builds His Dream House 1948 Cary Grant actor Jim Blandings 1
778945 Every Girl Should Be Married 1948 Cary Grant actor Dr. Madison Brown 1
778954 I Was a Male War Bride 1949 Cary Grant actor Capt. Henri Rochard 1

In [ ]:

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


In [98]:
len(cast[(cast.type == 'actor') &  (cast.year >= 1950) & (cast.year < 1960)])


Out[98]:
148779

In [ ]:

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


In [99]:
len(cast[(cast.type == 'actress') &  (cast.year >= 1950) & (cast.year < 1960)])


Out[99]:
54164

In [ ]:

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


In [100]:
len(cast[(cast.n == 1) & (cast.year <= 1980)])


Out[100]:
61602

In [ ]:

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


In [101]:
len(cast[~(cast.n == 1) & (cast.year <= 1980)])


Out[101]:
1052579

In [ ]:

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


In [102]:
len(cast[(cast.n.isnull()) & (cast.year <= 1980)])


Out[102]:
417826

In [10]:
cast.title.value_counts().head()


Out[10]:
Around the World in Eighty Days       1300
7 cajas                                689
Thelma                                 580
The Ten Commandments                   529
The Eschatrilogy: Book of the Dead     517
dtype: int64

In [11]:
titles[titles.title == 'Around the World in Eighty Days']


Out[11]:
title year
194246 Around the World in Eighty Days 1956

In [15]:
cast[(cast.title=="Around the World in Eighty Days") & (cast.n.isnull()) & ~(cast.character == 'Extra')& ~(cast.character == 'Minor Role')]


Out[15]:
title year name type character n
18565 Around the World in Eighty Days 1956 Philip Ahn actor Hong Kong Citizen NaN
102400 Around the World in Eighty Days 1956 Al Bain actor Saloon Patron NaN
231051 Around the World in Eighty Days 1956 Chet Brandenburg actor Seaman NaN
429122 Around the World in Eighty Days 1956 Campbell Cotts actor Reform Club Member NaN
636688 Around the World in Eighty Days 1956 Felix Felton actor Reform Club Member NaN
639156 Around the World in Eighty Days 1956 John (III) Ferguson actor Dancer NaN
654596 Around the World in Eighty Days 1956 Duke Fishman actor Marcher in Parade NaN
813743 Around the World in Eighty Days 1956 Paul Haakon actor Dancer NaN
855714 Around the World in Eighty Days 1956 Al Haskell actor Fireman in Parade NaN
881185 Around the World in Eighty Days 1956 Gitanillo Heredia actor Dancer NaN
907473 Around the World in Eighty Days 1956 Tex Holden actor One Legged Sailor NaN
920751 Around the World in Eighty Days 1956 Charles Horvath actor Stoker NaN
922419 Around the World in Eighty Days 1956 Shep Houghton actor Specialty Dancer NaN
991376 Around the World in Eighty Days 1956 Antonio Jiminez actor Dancer NaN
1076980 Around the World in Eighty Days 1956 Walter Kingsford actor Captain of the 'Mongolia' NaN
1174369 Around the World in Eighty Days 1956 Frederick Leister actor Reform Club Member NaN
1188181 Around the World in Eighty Days 1956 John C. Lewis actor Dancer NaN
1216517 Around the World in Eighty Days 1956 Richard Loo actor Hong Kong Saloon Manager NaN
1230633 Around the World in Eighty Days 1956 Keye Luke actor Old Man at Yokohama Travel Office NaN
1231988 Around the World in Eighty Days 1956 Charles Lunard actor Dancer NaN
1232872 Around the World in Eighty Days 1956 William Lundy actor Dancer NaN
1245490 Around the World in Eighty Days 1956 Casey MacGregor actor Train Fireman NaN
1250195 Around the World in Eighty Days 1956 Norman Macowan actor Reform Club Member NaN
1384498 Around the World in Eighty Days 1956 Frank Mills actor Barfly NaN
1419225 Around the World in Eighty Days 1956 Boyd 'Red' Morgan actor Stoker NaN
1565197 Around the World in Eighty Days 1956 Manuel Par?s actor Spanish Townsman NaN
1590243 Around the World in Eighty Days 1956 Jack Perrin actor Man on Sidewalk NaN
1688980 Around the World in Eighty Days 1956 Paul Rees actor Dancer NaN
1734754 Around the World in Eighty Days 1956 Edwin Rochelle actor Waiter NaN
1764994 Around the World in Eighty Days 1956 Joe Rudan actor Dancer NaN
1835331 Around the World in Eighty Days 1956 Arthur Sedinger actor Dancer NaN
1960755 Around the World in Eighty Days 1956 Robert Street actor Dancer NaN
2053103 Around the World in Eighty Days 1956 Michael Trubshawe actor Man Betting at Lloyd's NaN
2149668 Around the World in Eighty Days 1956 Richard Wattis actor Inspector Hunter NaN
2163675 Around the World in Eighty Days 1956 Dick Wessel actor Train Engineer NaN
2186509 Around the World in Eighty Days 1956 Imanos Williams actor Japanese Circus Performer NaN
2242379 Around the World in Eighty Days 1956 Zamba actor Lion NaN
2291914 Around the World in Eighty Days 1956 Marie Ardell actress Dance Extra NaN
2492755 Around the World in Eighty Days 1956 Lola De Ronda actress Dancer NaN
2496938 Around the World in Eighty Days 1956 Manuela DeHerey actress Dancer NaN
2522945 Around the World in Eighty Days 1956 Helene Drake actress Dancer NaN
2543333 Around the World in Eighty Days 1956 Dolores Ellsworth actress Dancer NaN
2576194 Around the World in Eighty Days 1956 Frances Fong actress Featured Player NaN
2695642 Around the World in Eighty Days 1956 Gretchen Houser actress Dancer NaN
2711461 Around the World in Eighty Days 1956 Leona Irwin actress Dancer NaN
2813762 Around the World in Eighty Days 1956 Virginia Ann Lee actress Dancer NaN
3038410 Around the World in Eighty Days 1956 Demita Prado actress Dancer NaN
3053443 Around the World in Eighty Days 1956 Anita Ramos actress Dancer NaN
3073136 Around the World in Eighty Days 1956 Suzanne Ridgeway actress Saloon Girl NaN
3289592 Around the World in Eighty Days 1956 Muriel Weldon actress Dancer NaN

In [ ]: