Skip to content
Investigating Netflix Movies and Guest Stars in The Office
  • AI Chat
  • Code
  • Report
  • 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).
    # Use this cell to begin your analysis, and add as many as you would like!
    # Import statements
    import matplotlib.pyplot as plt
    import pandas as pd
    import numpy as np
    Hidden output
    # Read in the data set
    office_episodes = pd.read_csv("datasets/office_episodes.csv")
    
    # Display office_episodes
    office_episodes
    # Extract the relevant information
    ep_no = office_episodes["episode_number"] # Episode numbers
    views = office_episodes["viewership_mil"] # Viewership in millions
    has_guests = office_episodes["has_guests"] # Boolean for whether or not pisode has a guest
    
    # Add column: rating_colour
    ratings_red = office_episodes["scaled_ratings"] < 0.25 # Episodes with rating < 0.25
    ratings_orange = np.logical_and(0.25 <= office_episodes["scaled_ratings"], office_episodes["scaled_ratings"] < 0.50) # Episodes with 0.25 <= ratings < 0.50
    ratings_lgreen = np.logical_and(0.50 <= office_episodes["scaled_ratings"], office_episodes["scaled_ratings"] < 0.75) # Episodes with 0.50 <= ratings < 0.75
    ratings_dgreen = office_episodes["scaled_ratings"] >= 0.75 # Episodes with ratings >= 0.75
    
    # Make an empty column for rating_color
    office_episodes["rating_colour"] = ""
    
    # Assign the colours to this column
    office_episodes["rating_colour"] = np.where(ratings_red, "red", office_episodes["rating_colour"])
    office_episodes["rating_colour"] = np.where(ratings_orange, "orange", office_episodes["rating_colour"])
    office_episodes["rating_colour"] = np.where(ratings_lgreen, "lightgreen", office_episodes["rating_colour"])
    office_episodes["rating_colour"] = np.where(ratings_dgreen, "darkgreen", office_episodes["rating_colour"])
    
    # Get the corresponding series data type
    rating_colour = office_episodes["rating_colour"]
    
    # Sizing system
    
    office_episodes["sizing_system"] = np.where(office_episodes["has_guests"], 250, 25)
    sizing_system = office_episodes["sizing_system"]
    # Plotting
    fig = plt.figure() 
    
    # Set figure parameters
    plt.rcParams['figure.figsize'] = [11, 7]
    
    # Scatter plot
    plt.scatter(ep_no, views, s=sizing_system, c=rating_colour)
    
    # Labels
    plt.xlabel("Episode Number")
    plt.ylabel("Viewership (Millions)")
    plt.title("Popularity, Quality, and Guest Appearances on the Office")
    # Question 2
    max_views = np.max(office_episodes["viewership_mil"]) # Maximum viewership
    max_views_ind = np.where(office_episodes["viewership_mil"] == max_views) # Index for max_views
    row_top_star = office_episodes.iloc[max_views_ind[0]] # Row in df that contains the top stars
    top_star = row_top_star[["guest_stars"]].iloc[0][0].split(",")[0] # Find one of the stars from the top episode
    top_star