len(cast)

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


titles.sort('year').head(2)

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


len(titles[titles['title'] == "Hamlet"])

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


len(titles[titles['title'] == "North by Northwest"])

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


titles[titles['title'] == "Hamlet"].sort("year").head(1)

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


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

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


len(titles[titles.year ==1950])

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


len(titles[titles.year ==1960])

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


len(titles[(titles.year >=1950) & (titles.year <=1959)])
# t = titles
# len(t[(t.year >= 1950) & (t.year <= 1959)])

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


titles[titles.title == "Batman"].year

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


len(cast[cast["title"] == "Inception"]) 




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


len(cast[cast.n.isnull()][cast["title"] == "Inception"])

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


len(cast[cast.n.notnull()][cast.title == "Inception"])

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


cast[cast.title == "North by Northwest" ][cast.n.notnull()].sort('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)][cast.n.notnull()].sort("n")

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


cast[(cast.title == "Sleuth") & (cast.year == 2007)][cast.n.notnull()].sort("n")

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


len(cast[(cast.title == "Hamlet") & (cast.year == 1921)][cast.n.notnull()])

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


len(cast[(cast.title == "Hamlet") & (cast.year == 1996)][cast.n.notnull()])

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


len(cast[cast.character == "Hamlet"])

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


len(cast[cast.character == "Ophelia"] )

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


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

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


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

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



c = cast
c = c[c.name == 'Sidney Poitier']
len(c)

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



c = cast
c = c[c.name == 'Judi Dench']
len(c)

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



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

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


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

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


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

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


len(cast[(cast.type == "actress") &(cast.year >=1940) & (cast.year <1950)])

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


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

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


len(cast[(cast.n!=1)&(cast.year <=1980)])

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


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


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


