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).
    # import the libraries
    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    Hidden output
    # read the data into a pandas dataframe
    office = pd.read_csv("datasets/office_episodes.csv")
    office.head()
    # create the colors for the scaled ratings
    scaled_ratings = office['scaled_ratings']
    colors = []
    
    for rating in scaled_ratings:
        if rating < 0.25:
            colors.append('red')
        elif rating < 0.5:
            colors.append('orange')
        elif rating < 0.75:
            colors.append('lightgreen')
        else:
            colors.append('darkgreen')
    # create the sizing system
    sizes = [250 if appearance else 25 for appearance in office['has_guests']]
    Hidden output
    # create a scatterplot
    fig = plt.figure()
    plt.scatter(office['episode_number'], office['viewership_mil'], c = colors, s=sizes)
    
    # Set the title and axis labels
    plt.title("Popularity, Quality, and Guest Appearances on the Office")
    plt.xlabel("Episode Number")
    plt.ylabel("Viewership (Millions)")
    plt.show()
    # create a dataframe that has guest
    guest_episodes = office[office['has_guests'] == True]
    guest_episodes.head()
    # now i sort the guest_episodes dataframe using the viewership
    # in descending order
    most_watched = guest_episodes.sort_values(by='viewership_mil', ascending= False)
    most_watched.set_index('episode_number')
    most_watched.head(3)
    # now i can take the top entry 
    top_stars = most_watched.iloc[0]['guest_stars']
    print(top_stars)
    top_list = top_stars.split(',')
    print(top_list)
    top_star = top_list[0]
    print(top_star)