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 as pd
office_df = pd.read_csv("datasets/office_episodes.csv") #laod the dataset as a dataframe.
print(office_df[:5]) #check if the dataset is loaded and what it looks like
#filter the dataset to the relevant columns only
filtered_office_df = office_df.loc[:, ["episode_number", "season", "episode_title",
"viewership_mil", "guest_stars", "has_guests", "scaled_ratings"]]
#check if it was filtered properly
print(filtered_office_df[0:5])
#create an empty list for colors derived from scaled_ratings column
colors = []
#create an empty list for marker size based on if the episode has a guest star
sizes = []
#using for loop to append colors list and sizes list
for key, row in filtered_office_df.iterrows():
#conditions for colors
if row["scaled_ratings"] >= 0.75:
colors.append("darkgreen")
elif row["scaled_ratings"] >= 0.50 and row["scaled_ratings"] < 75:
colors.append("lightgreen")
elif row["scaled_ratings"] >= 0.25 and row["scaled_ratings"] < 50:
colors.append("orange")
else:
colors.append("red")
#conditions for sizes
if row["has_guests"] == True:
sizes.append(250)
else:
sizes.append(25)
#checking if the lists are appended
print(colors[0:10])
print(sizes[0:10])
import matplotlib.pyplot as plt
fig = plt.figure()
plt.rcParams['figure.figsize'] = [15, 10]
#plot scatter and labels
plt.scatter(filtered_office_df["episode_number"], filtered_office_df["viewership_mil"], s=sizes,
c=colors, marker="*")
plt.title("Popularity, Quality, and Guest Appearances on the Office")
plt.xlabel("Episode Number")
plt.ylabel("Viewership (Millions)")
#show plot
plt.show()
#check row with highest viewership
print(filtered_office_df.loc[filtered_office_df["viewership_mil"] ==
max(filtered_office_df["viewership_mil"]) ])
#name of one of the guest in the episode with the highest veiwership
top_star = "Jessica Alba"