<jupyter_start><jupyter_text>Download the data and load it to Pandas. You can find them [here](https://drive.google.com/file/d/1NY6cmF9Shjw-dD7BD6bNmfcIVz-kQcFR/view?usp=sharing).<jupyter_code>titles = pd.read_csv('data/titles.csv', index_col=None)
titles.head()
cast = pd.read_csv('data/cast.csv', index_col=None)
cast.head()<jupyter_output><empty_output><jupyter_text>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?<jupyter_code>filter_movies = (cast['character'] =='Superman') | (cast['character'] == 'Batman')
super_df = cast[filter_movies][['year','character']].groupby(['year','character']).size()
super_df = super_df.unstack()
super_df = super_df.fillna(0)
super_df.head()
counts = super_df.Superman - super_df.Batman
print(f'Superman years: {len(counts[counts > 0.0])}')<jupyter_output>Superman years: 11<jupyter_text>How many years have been "Batman years", with more Batman characters than Superman characters?<jupyter_code>print(f'Batman years: {len(counts[counts < 0.0])}')<jupyter_output>Batman years: 26<jupyter_text>Count the number of actor roles each year and the number of actress roles each year over the history of film.<jupyter_code>roles = cast.groupby(['year','type']).size()
roles = roles.unstack('type')
roles = roles.fillna(0)
roles<jupyter_output><empty_output><jupyter_text>Find the difference between the number of actor roles each year and the number of actress roles each year over the history of film.<jupyter_code>roles = cast.groupby(['year','type']).size()
roles = roles.unstack('type')
roles = roles.fillna(0)
difference = (roles.actor - roles.actress)
difference<jupyter_output><empty_output><jupyter_text>What is the fraction of roles that have been 'actor' roles each year in the history of film.<jupyter_code>roles = cast.groupby(['year','type']).size()
roles = roles.unstack('type')
roles = roles.fillna(0)
fraction = roles.actor / (roles.actor + roles.actress)
fraction<jupyter_output><empty_output><jupyter_text>What is the fraction of supporting (n=2) roles that have been 'actor' roles each year in the history of film.<jupyter_code>filter_n = cast['n'] == 2
roles = cast[filter_n].groupby(['year','type']).size()
roles = roles.unstack('type')
roles = roles.fillna(0)
fraction = roles.actor / (roles.actor + roles.actress)
fraction<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13911960132890366, 'fraction_numerical': 0.008305647840531562, 'mean_word_length': 7.1661016949152545, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '111999', 'license': 'MIT', 'n_tokens_mistral': 856, 'n_tokens_neox': 829, 'n_words': 199, 'path': 'Pandas/6.3 Exercises-5.ipynb', 'repo_name': 'robynmundle/data_science', 'size': '2408'}