<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Define a year as a "Superman year" whose films feature more Superman characters than Batman. How many years in film history have been Superman years?
Step1:  How many years have been "Batman years", with more Batman characters than Superman characters?
Step2:  Plot the number of actor roles each year and the number of actress roles each year over the history of film.
Step3:  Plot the number of actor roles each year and the number of actress roles each year, but this time as a kind='area' plot.
Step4:  Plot the difference between the number of actor roles each year and the number of actress roles each year over the history of film.
Step5:  Plot the fraction of roles that have been 'actor' roles each year in the hitsory of film.
Step6:  Plot the fraction of supporting (n=2) roles that have been 'actor' roles each year in the history of film.
Step7:  Build a plot with a line for each rank n=1 through n=3, where the line shows what fraction of that rank's roles were 'actor' roles for each year in the history of film.
<ASSISTANT_TASK:>
Python Code:
both = cast[(cast.character=='Superman') | (cast.character == 'Batman')].groupby(['year','character']).size().unstack().fillna(0)
diff = both.Superman - both.Batman
print("Superman: " + str(len(diff[diff>0])))
Explanation: Define a year as a "Superman year" whose films feature more Superman characters than Batman. How many years in film history have been Superman years?
End of explanation
both = cast[(cast.character=='Superman') | (cast.character == 'Batman')].groupby(['year','character']).size().unstack().fillna(0)
diff = both.Batman - both.Superman
print("Batman: " + str(len(diff[diff>0])))
Explanation: How many years have been "Batman years", with more Batman characters than Superman characters?
End of explanation
cast.groupby(['year','type']).size().unstack().plot()
Explanation: Plot the number of actor roles each year and the number of actress roles each year over the history of film.
End of explanation
cast.groupby(['year','type']).size().unstack().plot(kind='area')
Explanation: Plot the number of actor roles each year and the number of actress roles each year, but this time as a kind='area' plot.
End of explanation
foo = cast.groupby(['year','type']).size().unstack().fillna(0)
foo['diff'] = foo['actor']-foo['actress']
foo['diff'].plot()
Explanation: Plot the difference between the number of actor roles each year and the number of actress roles each year over the history of film.
End of explanation
foo['totalRoles'] = foo['actor']+foo['actress']
foo['manFrac'] = foo['actor']/foo['totalRoles']
foo['manFrac'].plot()
Explanation: Plot the fraction of roles that have been 'actor' roles each year in the hitsory of film.
End of explanation
support = cast[cast.n==2]
bar = support.groupby(['year','type']).size().unstack().fillna(0)
bar['totalRoles'] = bar['actor']+bar['actress']
bar['manFrac'] = bar['actor']/bar['totalRoles']
bar['manFrac'].plot()
Explanation: Plot the fraction of supporting (n=2) roles that have been 'actor' roles each year in the history of film.
End of explanation
thirdWheel = cast[cast.n==3]
baz = thirdWheel.groupby(['year','type']).size().unstack().fillna(0)
baz['totalRoles'] = baz['actor']+baz['actress']
baz['manFrac'] = baz['actor']/baz['totalRoles']
foo['manFrac'].plot() + (bar['manFrac'].plot() + baz['manFrac'].plot())
Explanation: Build a plot with a line for each rank n=1 through n=3, where the line shows what fraction of that rank's roles were 'actor' roles for each year in the history of film.
End of explanation
<END_TASK>