How Long is Too Long?

#Discover API url and headers
url = ''
headers = {'Authorization': 'Bearer {}'.format(access_token),
'Content-Type': 'application/json;charset=utf-8'}
def get_num_pages(url, headers, start_date, end_date):
Takes as input an API url, headers containing
authentication information, a start date, and end date.
Returns the number of pages of results returned by the
API call as an int.
params = {'release_date.gte': start_date,
'release_date.lte': end_date}
returned_movies = requests.get(url=url, headers=headers,
return returned_movies['total_pages']
def get_movies_data(start_date, end_date, url, headers):
Takes a start date, end date, API url, and headers with
authentication information.
Uses get_num_pages function to check the number of pages
returned by the API.
Loops through all pages, requesting data from API, concatenating
results to a dataframe.
Returns dataframe of movie information between start and end
df = pd.DataFrame()
num_pages = get_num_pages(url, headers, start_date, end_date)
for i in range(1, num_pages+1):
parameters = {'release_date.gte': start_date,
'release_data.lte': end_date,
'page': i}
request = requests.get(url, headers=headers,
df = pd.concat([df, pd.DataFrame(request['results'])],
return df
def create_quarter_date_list(year):
Returns a list of quarterly start dates and a list of
quarterly end dates from int input representing year.
start_dates = [f'{year}-01-01', f'{year}-04-01',
f'{year}-07-01', f'{year}-10-01']
end_dates = [f'{year}-03-31', f'{year}-06-30',
f'{year}-09-30', f'{year}-12-31']
return start_dates, end_dates
#create start and end dates for 2000 to 2020
start_dates = []
end_dates = []
for year in range(2000, 2021):
start_date, end_date = create_quarter_date_list(year)
start_dates += start_date
end_dates += end_date
#get movie data and concat to current dataframe
df = pd.DataFrame()
url = ''
#loop through all start and end dates and make an API call for each date range
#append results to df
for i, start_date in enumerate(start_dates):
temp_df = get_movies_data(start_date=start_date,
df = pd.concat([df, temp_df], sort=False)
DataFrame showing results of first API calls
url = ''
movie_details = []#loop through all movie IDs, request details, and append to movie_details
for index, movie_id in enumerate(movies['id']):
response = requests.get(f'{url}/{movie_id}',
update_progress(index / len(movies['id']))
movies_df = pd.DataFrame(movie_details)
movies_df['imdb_id'].fillna('missing', inplace=True)
runtime_df = runtime_df.loc[runtime_df['revenue'] > 0]
movies_lt_30 = runtime_df.loc[runtime_df['runtime'] <= 30]
movies_lt_60 = runtime_df.loc[(runtime_df['runtime'] > 30) &
(runtime_df['runtime'] <= 60)]
movies_lt_90 = runtime_df.loc[(runtime_df['runtime'] > 60) &
(runtime_df['runtime'] <= 90)]
movies_lt_120 = runtime_df.loc[(runtime_df['runtime'] > 90) &
(runtime_df['runtime'] <= 120)]
movies_lt_150 = runtime_df.loc[(runtime_df['runtime'] > 120) &
(runtime_df['runtime'] <= 150)]
movies_lt_180 = runtime_df.loc[(runtime_df['runtime'] > 150) &
(runtime_df['runtime'] <= 180)]
movies_gt_180 = runtime_df.loc[(runtime_df['runtime'] > 180)]




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to access your AWS account

Challenges and opportunities for digital transformation within the public sector

A typical red phone booth

Linting in Flutter for Maintain a Healthy Codebase

Why coding and kindness go hand in hand, and how I learned to be kind to myself

What is Kubernetes?

End to End ML using AWS

Setup Logstash on DigitalOcean with a Rails App hosted on Heroku

10 of my best Twitter threads

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kai Graham

Kai Graham

More from Medium


Have you ever got a discount from Starbucks ?

Proving global warming is not based on data and science

Why choose random_state ?