Skip to content
Investigating Netflix Movies and Guest Stars in The Office
  • AI Chat
  • Code
  • Report
  • 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 matplotlib.pyplot as plt
    import numpy as np
    import pandas as pd
    office_data = pd.read_csv("datasets/office_episodes.csv")
    office_data.loc[office_data.guest_stars.isna(), ["guest_stars", "has_guests"]].describe()
    office_data.loc[office_data.guest_stars.notna(), ["guest_stars", "has_guests"]].describe()
    def colorize(rating):
        """Define color of the point based on rating."""
        if rating < .25:
            return "red"
        if (.25 <= rating < .5):
            return "orange"
        if (.5 <= rating < .75):
            return "lightgreen"
        if (rating >= .75):
            return "darkgreen"
    def marker_size(has_guest):
        """Define marker size based on guest existance."""
        if has_guest:
            return 250
        return 25
    fig, ax = plt.subplots(figsize=(11, 7))
    colors = office_data.scaled_ratings.apply(colorize).tolist()
    markersizes = office_data.has_guests.apply(marker_size).tolist()
    most_viewed = office_data.loc[
        office_data.viewership_mil == office_data.viewership_mil.max()
    top_star = most_viewed.guest_stars.item().split(", ")[0]
        xy=(most_viewed.episode_number, most_viewed.viewership_mil),
        xytext=(most_viewed.episode_number, most_viewed.viewership_mil-1)
    plt.title("Popularity, Quality, and Guest Appearances on the Office")
    plt.xlabel("Episode Number")
    plt.ylabel("Viewership (Millions)")