Viesturs Eglitis/

Investigating Netflix Movies and Guest Stars in The Office


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

Importing the required modules for analysis:

import matplotlib.pyplot as plt
import pandas as pd
Hidden output

Loading the .csv file and defining/saving the dataframe; defining the sorting algorithm, coloring for each rating bracket, sizing data points

office_episodes = pd.read_csv('datasets/office_episodes.csv')
colors = []
for rating in office_episodes['scaled_ratings']:
    if rating < 0.25:
    elif rating < 0.5:
    elif rating < 0.75:

size = []
shape = []
for guest in office_episodes['guest_stars'].isnull():
    if guest == True:

Design a scatter plot

fig = plt.figure()
plt.scatter(office_episodes['episode_number'], office_episodes['viewership_mil'], color = colors, s = size)
plt.xlabel('Episode Number')
plt.ylabel('Viewership (Millions)')
plt.title("Popularity, Quality, and Guest Appearances on the Office")

Select the guest stars in the most watched episode

sorted_episodes_by_viewership = office_episodes.sort_values(by='viewership_mil', ascending=False)
top_stars_most_viewed = sorted_episodes_by_viewership.iloc[0][9]
top_star = top_stars_most_viewed.split(',')[0]
  • AI Chat
  • Code