1. Welcome!
.
The Office! What started as a British mockumentary series about office culture in 2001 has since spawned ten other variants across the world, including an Israeli version (2010-13), a Hindi version (2019-), and even a French Canadian variant (2006-2007). Of all these iterations (including the original), the American series has been the longest-running, spanning 201 episodes over nine seasons.
In this notebook, we will take a look at a dataset of The Office episodes, and try to understand how the popularity and quality of the series varied over time. To do so, we will use the following dataset: datasets/office_episodes.csv
, which was downloaded from Kaggle here.
This dataset contains information on a variety of characteristics of each episode. In detail, these are:
- episode_number: Canonical episode number.
- season: Season in which the episode appeared.
- episode_title: Title of the episode.
- description: Description of the episode.
- ratings: Average IMDB rating.
- votes: Number of votes.
- viewership_mil: Number of US viewers in millions.
- duration: Duration in number of minutes.
- release_date: Airdate.
- guest_stars: Guest stars in the episode (if any).
- director: Director of the episode.
- writers: Writers of the episode.
- has_guests: True/False column for whether the episode contained guest stars.
- scaled_ratings: The ratings scaled from 0 (worst-reviewed) to 1 (best-reviewed).
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = [11, 7]
office_df = pd.read_csv('datasets/office_episodes.csv')
office_df.head()
office_df.info()
cols_tes = []
for ind, row in office_df.iterrows():
print(office_df['episode_title'])
cols = []
# Iterate through the DataFrame, and assign colors based on the rating
for ind, row in office_df.iterrows():
if row['scaled_ratings'] < 0.25:
cols.append('red')
elif row['scaled_ratings'] < 0.50:
cols.append('orange')
elif row['scaled_ratings'] < 0.75:
cols.append('lightgreen')
else:
cols.append('darkgreen')
cols[:10]
fig = plt.figure()
plt.scatter(x=office_df['episode_number'], y=office_df['viewership_mil'])
plt.show()
fig = plt.figure()
# get colors from previous code
plt.scatter(x=office_df['episode_number'], y=office_df['viewership_mil'], c=cols)
plt.show()
sizes = []
# Iterate through the DataFrame, and assign a size based on whether it has guests
for ind, row in office_df.iterrows():
if row['has_guests'] == False:
sizes.append(25)
else:
sizes.append(250)
sizes[:10]
fig = plt.figure()
# add sizes
plt.scatter(x=office_df['episode_number'], y=office_df['viewership_mil'],
c=cols, s=sizes)
plt.show()
fig = plt.figure()
# add sizes
plt.scatter(x=office_df['episode_number'], y=office_df['viewership_mil'],
c=cols, s=sizes)
# add label
plt.title("Popularity, Quality, and Guest Appearances on the Office")
plt.xlabel("Episode Number")
plt.ylabel("Viewership (Millions)")
plt.show()
fig = plt.figure()
# not best option to have release_year as the x-axis (string not date form)
plt.scatter(x=office_df['release_date'], y=office_df['viewership_mil'],
c=cols, s=sizes)
# add label
plt.title("Popularity, Quality, and Guest Appearances on the Office")
plt.xlabel("Episode Number")
plt.ylabel("Viewership (Millions)")
plt.show()
# parsing dates
office_df = pd.read_csv('datasets/office_episodes.csv', parse_dates=['release_date'])
office_df.info()
fig = plt.figure()
# not best option to have release_year as the x-axis (string not date form)
plt.scatter(x=office_df['release_date'], y=office_df['viewership_mil'],
c=cols, s=sizes)
# add label
plt.title("Popularity, Quality, and Guest Appearances on the Office")
plt.xlabel("Episode Number")
plt.ylabel("Viewership (Millions)")
plt.show()
# adding new fields
office_df['colors'] = cols
office_df['sizes'] = sizes
office_df.info()
# Split data into guest and non_guest DataFrames
non_guest_df = office_df[office_df['has_guests'] == False]
guest_df = office_df[office_df['has_guests'] == True]