# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import pandas as pd

# ### 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).

titles = pd.read_csv('data/titles.csv')
titles.head()

cast = pd.read_csv('data/cast.csv')
cast.head()

# ### Using groupby(), count the number of films that have been released each decade in the history of cinema.

titles['title'].groupby((titles['year']//10)*10).count()

# ### Use groupby() count the number of "Hamlet" films made each decade.

filter_hamlet = titles['title'] == 'Hamlet'
titles[filter_hamlet]['title'].groupby((titles['year']//10)*10).count()

# ### How many leading (n=1) roles were available to actors, and how many to actresses, in each year of the 1950s?

filters = (cast['n'] == 1) & (cast['year'].between(1950,1959))
cast[filters][['year','type']].groupby(['year','type']).size()

# ### In the 1950s decade taken as a whole, how many total roles were available to actors, and how many to actresses, for each "n" number 1 through 5?

filters = (cast['n'].between(1,5)) & (cast['year'].between(1950,1959))
cast[filters][['n','type']].groupby(['n','type']).size()

# ### Use groupby() to determine how many roles are listed for each of the Pink Panther movies.

filter_panther = (cast['title'] == 'The Pink Panther')
cast[filter_panther][['year','type']].groupby('year').count() #[['year','type']]

# ### List, in order by year, each of the films in which <NAME> has played more than 1 role.

filter_oz = (cast['name'] == '<NAME>')
x = cast[filter_oz][['year','title']].groupby('title').size()
x[x>1]

# ### List each of the characters that <NAME> has portrayed at least twice.

x = cast[filter_oz]['character'].value_counts()
x[x>1]

StarcoderdataJupyterScriptsDedupFiltered