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).
# Use this cell to begin your analysis, and add as many as you would like!

import pandas as pd

import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = [11, 7]
# Importing office dataset
df_office = pd.read_csv('datasets/office_episodes.csv')

# first five rows of office dataset
df_office.head()
# summary of office dataset
df_office.info()


plt.scatter(df_office['episode_number'], df_office['viewership_mil'])
plt.show()
# adding an array of colors to our plot
cols = []

for ind, row in df_office.iterrows() :
    if row['scaled_ratings'] < 0.25 :
        cols.append('red')
    elif row['scaled_ratings'] >= 0.25 and row['scaled_ratings'] < 0.50 :
        cols.append('orange')
    elif row['scaled_ratings'] >= 0.50 and row['scaled_ratings'] < 0.75 :
        cols.append('lightgreen')
    else :
        cols.append('darkgreen')
# list of colors corresponding to our links to the plot
print(cols)
# adding colors to our plot


plt.scatter(df_office['episode_number'], df_office['viewership_mil'], c = cols)
plt.show()
# size list
sizes = []

for ind, row in df_office.iterrows() :
    if row['has_guests'] == True :
        sizes.append(250)
    else :
        sizes.append(25)
        
# list of sizes corresponding to our links to the plot
print(sizes)
# Adding sizes to our plot


plt.scatter(df_office['episode_number'], df_office['viewership_mil'], c = cols, s = sizes)
plt.show()
# Adding a title, x - axis lable and y-axis label


plt.scatter(df_office['episode_number'], df_office['viewership_mil'], c = cols, s = sizes)
plt.title('Popularity, Quality, and Guest Appearances on the Office')
plt.xlabel('Episode Number')
plt.ylabel('Viewership (Millions)')
plt.show()
df_office['colors'] = cols
df_office['sizes'] = sizes

df_office.info()
# getting non_guest data
df_non_guest = df_office[df_office['has_guests'] == False]

# getting guest dataframe
df_guest = df_office[df_office['has_guests'] == True]
# Differenciating guest appearances with size and a star
fig = plt.figure()

# Adding a plot sytle from 'ggplot'
plt.style.use('ggplot')

plt.scatter(df_non_guest['episode_number'], 
            df_non_guest['viewership_mil'], 
            c = df_non_guest['colors'], 
            s = df_non_guest['sizes']
           )

plt.scatter(df_guest['episode_number'], 
            df_guest['viewership_mil'], 
            c = df_guest['colors'], 
            s = df_guest['sizes'],
            marker = '*'
           )

plt.title('Popularity, Quality, and Guest Appearances on the Office')
plt.xlabel('Episode Number')
plt.ylabel('Viewership (Millions)')
plt.show()