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).
# Use this cell to begin your analysis, and add as many as you would like!
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv('datasets/office_episodes.csv')
episode_number = list(df['episode_number'])
viewership_mil = list(df['viewership_mil'])
has_guest = list(df['has_guests'])
guest_star = list(df['guest_stars'])
size = []
for i in range(188):
if has_guest[i] == True:
size.append(250)
else:
size.append(25)
rat_col = []
ratings = list(df['scaled_ratings'])
for i in range(188):
if ratings[i] < 0.25:
rat_col.append('red')
elif ratings[i] < 0.5:
rat_col.append('orange')
elif ratings[i] < 0.75:
rat_col.append('lightgreen')
else: rat_col.append('darkgreen')
fig = plt.figure()
plt.scatter(episode_number, viewership_mil, s = size, c = rat_col)
plt.title("Popularity, Quality, and Guest Appearances on the Office")
plt.xlabel('Episode Number')
plt.ylabel('Viewership (Millions)')
top_star_index = viewership_mil.index(max(viewership_mil))
top_star = guest_star[top_star_index]
top_star = top_star.split(', ')
top_star = top_star[0]
top_star = ' ' + top_star
plt.text(top_star_index, max(viewership_mil), top_star)
plt.show()