Skip to content

1. Welcome!

Markdown.

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:

datasets/office_episodes.csv
  • 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 mathplotlib and pandas as aliases 
import matplotlib.pyplot as plt
import pandas as pd

# Read in the CSV as a DataFrame
episodes = pd.read_csv('datasets/office_episodes.csv')

#Convert the dataset into DataFrame
episodes_df = pd.DataFrame(episodes)
# Print the first five rows of the DataFrame
episodes_df.head()
# Define an empty list
colors = []
marker_size = []

# Iterate over rows of netflix_movies_col_subset
for index, row in episodes_df.iterrows():
    if row['scaled_ratings'] < 0.25 :
        colors.append("red")
    elif row['scaled_ratings'] < 0.50:
        colors.append("orange")
    elif row['scaled_ratings'] < 0.75:
        colors.append("lightgreen")
    else:
        colors.append("darkgreen")
        
    if row['has_guests'] == True:
        marker_size.append(250)
    else:
        marker_size.append(25)
        
# Inspect the first 10 values in your list        
print(colors[:10])
marker_size[:10]
# Create a figure and increase the figure size
fig = plt.figure()
plt.style.use('fivethirtyeight')
plt.rcParams['figure.figsize'] = [11, 7]

# Create a scatter plot of duration versus year
plt.scatter(x=episodes_df['episode_number'], y=episodes_df['viewership_mil'], c=colors, s=marker_size)

# Create a title and axis labels
plt.title("Popularity, Quality, and Guest Appearances on the Office")
plt.xlabel("Episode Number")
plt.ylabel("Viewership (Millions)")

# Show the plot
plt.show()
top_guest = episodes_df['guest_stars'][episodes_df['viewership_mil'].idxmax()]
top_guest
top_star = 'Jack Black'
Hidden output