titles.shape[0]

"""
Explanation: How many movies are listed in the titles dataframe?
End of explanation
"""


titles.sort(columns='year')[0:2]

"""
Explanation: What are the earliest two films listed in the titles dataframe?
End of explanation
"""


titles[titles['title']=='Hamlet'].shape[0]

"""
Explanation: How many movies have the title "Hamlet"?
End of explanation
"""


titles[titles['title']=='North by Northwest'].shape[0]

"""
Explanation: How many movies are titled "North by Northwest"?
End of explanation
"""


titles[titles['title']=='Hamlet'].sort(columns='year')['year'].values[0]

"""
Explanation: When was the first movie titled "Hamlet" made?
End of explanation
"""


titles[titles['title']=='Treasure Island'].sort(columns='year')

"""
Explanation: List all of the "Treasure Island" movies from earliest to most recent.
End of explanation
"""


titles[titles['year']==1950].shape[0]

"""
Explanation: How many movies were made in the year 1950?
End of explanation
"""


titles[titles['year']==1960].shape[0]

"""
Explanation: How many movies were made in the year 1960?
End of explanation
"""


titles[(titles['year']>1950)&(titles['year']<1960)].shape[0]

"""
Explanation: How many movies were made from 1950 through 1959?
End of explanation
"""


print(titles[titles['title']=="Batman"]['year'].values)

"""
Explanation: In what years has a movie titled "Batman" been released?
End of explanation
"""


cast[(cast['title']=="Inception")&(cast['year']==2010)].shape[0]

"""
Explanation: How many roles were there in the movie "Inception"?
End of explanation
"""


sum(cast[(cast['title']=="Inception")&(cast['year']==2010)]['n'].isnull())

"""
Explanation: How many roles in the movie "Inception" are NOT ranked by an "n" value?
End of explanation
"""


sum(cast[(cast['title']=="Inception")&(cast['year']==2010)]['n'].notnull())

"""
Explanation: But how many roles in the movie "Inception" did receive an "n" value?
End of explanation
"""


cast[cast['title']=='North by Northwest'].dropna().sort(columns='n')

"""
Explanation: Display the cast of "North by Northwest" in their correct "n"-value order, ignoring roles that did not earn a numeric "n" value.
End of explanation
"""


cast[(cast['title']=='Sleuth')&(cast['year']==1972)].sort(columns='n')

"""
Explanation: Display the entire cast, in "n"-order, of the 1972 film "Sleuth".
End of explanation
"""


cast[(cast['title']=='Sleuth')&(cast['year']==2007)].sort(columns='n')

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


cast[(cast['title']=='Hamlet')&(cast['year']==1921)].shape[0]

"""
Explanation: How many roles were credited in the silent 1921 version of Hamlet?
End of explanation
"""


cast[(cast['title']=='Hamlet')&(cast['year']==1996)].shape[0]

"""
Explanation: How many roles were credited in Branagh’s 1996 Hamlet?
End of explanation
"""


cast[(cast['character']=='Hamlet')].shape[0]

"""
Explanation: How many "Hamlet" roles have been listed in all film credits through history?
End of explanation
"""


cast[(cast['character']=='Ophelia')]['name'].unique().shape[0]

"""
Explanation: How many people have played an "Ophelia"?
End of explanation
"""


cast[(cast['character']=='The Dude')]['name'].unique().shape[0]

"""
Explanation: How many people have played a role called "The Dude"?
End of explanation
"""


cast[(cast['character']=='The Stranger')]['name'].unique().shape[0]

"""
Explanation: How many people have played a role called "The Stranger"?
End of explanation
"""


cast[(cast['name']=='Sidney Poitier')]['character'].unique().shape[0]

"""
Explanation: How many roles has Sidney Poitier played throughout his career?
End of explanation
"""


cast[(cast['name']=='Judi Dench')]['character'].unique().shape[0]

"""
Explanation: How many roles has Judi Dench played?
End of explanation
"""


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

"""
Explanation: List the supporting roles (having n=2) played by Cary Grant in the 1940s, in order by year.
End of explanation
"""


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

"""
Explanation: List the leading roles that Cary Grant played in the 1940s in order by year.
End of explanation
"""


cast[(cast['type']=='actor')&(cast['year']>=1940)&(cast['year']<1950)].shape[0]

"""
Explanation: How many roles were available for actors in the 1950s?
End of explanation
"""


cast[(cast['type']=='actress')&(cast['year']>=1940)&(cast['year']<1950)].shape[0]

"""
Explanation: How many roles were avilable for actresses in the 1950s?
End of explanation
"""


cast[(cast['n']==1)&(cast['year']<=1980)].shape[0]

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


cast[(cast['n']!=1)&(cast['year']<=1980)].shape[0]

"""
Explanation: How many non-leading roles were available through from the beginning of film history through 1980?
End of explanation
"""


sum(cast[(cast['year']<=1980)]['n'].isnull())

"""
Explanation: How many roles through 1980 were minor enough that they did not warrant a numeric "n" rank?
End of explanation
"""


