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 pandas and the csv
import pandas as pd
office_episodes = pd.read_csv("datasets/office_episodes.csv")
print(office_episodes.head())
#episode number, viewership, scaled ratings, guest_stars, has_guests
office_episodes_less = office_episodes[["episode_number", "viewership_mil", "scaled_ratings", "guest_stars", "has_guests"]]
print(office_episodes_less.head())
#color scheme for scaled ratings
color = []
for index,row in office_episodes_less.iterrows():
if row["scaled_ratings"] >= 0.75:
color.append("darkgreen")
elif row["scaled_ratings"] >= 0.5 and row["scaled_ratings"] < 0.75:
color.append("lightgreen")
elif row["scaled_ratings"] >= 0.25 and row["scaled_ratings"] < 0.5:
color.append("orange")
else:
color.append("red")
print(color)
#Sizing system
size = []
for index,row in office_episodes_less.iterrows():
if row["has_guests"] == True:
size.append(250)
else:
size.append(25)
#plot
import matplotlib.pyplot as plt
fig = plt.figure()
plt.scatter(office_episodes_less["episode_number"],office_episodes_less["viewership_mil"], size, color, marker = "x")
plt.title("Popularity, Quality, and Guest Appearances on the Office")
plt.xlabel("Episode Number")
plt.ylabel("Viewership (Millions)")
#top star
top_star_val = office_episodes_less["viewership_mil"].agg(max)
top_star_temp = office_episodes_less.loc[office_episodes_less["viewership_mil"] == top_star_val, "guest_stars"].iloc[0]
print(top_star_temp)
top_star = "Cloris Leachman"