Netflix! What started in 1997 as a DVD rental service has since exploded into one of the largest entertainment and media companies.
Given the large number of movies and series available on the platform, it is a perfect opportunity to flex your exploratory data analysis skills and dive into the entertainment industry. Our friend has also been brushing up on their Python skills and has taken a first crack at a CSV file containing Netflix data. They believe that the average duration of movies has been declining. Using your friends initial research, you'll delve into the Netflix data to see if you can determine whether movie lengths are actually getting shorter and explain some of the contributing factors, if any.
You have been supplied with the dataset netflix_data.csv
, along with the following table detailing the column names and descriptions:
The data
netflix_data.csv
Column | Description |
---|---|
show_id | The ID of the show |
type | Type of show |
title | Title of the show |
director | Director of the show |
cast | Cast of the show |
country | Country of origin |
date_added | Date added to Netflix |
release_year | Year of Netflix release |
duration | Duration of the show in minutes |
description | Description of the show |
genre | Show genre |
Step 1: Loading the CSV file and store as netflix_df.
# Importing pandas and matplotlib
import pandas as pd
import matplotlib.pyplot as plt
# Loading the CSV file and storing it as netflix_df
netflix_df = pd.read_csv('netflix_data.csv')
netflix_df.head()
Step 2: Filtering the data
Removing the rows containing the category 'TV shows', leaving only Movies, and storing the modified dataframe as netflix_subset.
netflix_subset = netflix_df.drop(netflix_df[netflix_df['type']=='TV Show'].index)
netflix_subset.head()
Step 3: Isolating columns for Exploratory Analysis
Keeping only the columns "title", "country", "genre", "release_year", "duration", and saving this into a new DataFrame called netflix_movies.
netflix_movies = netflix_subset[["title", "country", "genre", "release_year", "duration"]]
netflix_movies.head()
Step 4: Dropping movies shorter than 60 minutes.
Filtering the netflix_movies dataframe to find the movies that are shorter than 60 minutes, then saving the resulting DataFrame as short_movies
short_movies = netflix_movies[netflix_movies['duration']<60]
short_movies.head()
Step 5: Data Preparation for Visualization
Creating a list named 'colors' by using a 'for loop' with if/elif statements that iterates through the values of the 'genre' column, assigning colors for every value: "Children" -> 'yellow', "Documentaries" -> 'blue', "Stand-Up" -> 'orange', and "Other" -> 'grey' - for everything else).
colors = []
for x in netflix_movies['genre']:
if x == 'Children':
colors.append('yellow')
elif x == 'Documentaries':
colors.append('blue')
elif x == 'Stand-Up':
colors.append('orange')
else:
colors.append('grey')
print(colors[:10])
Step 6: Creating a Visualization for Analysis
Creating a scatter plot with the title "Movie Duration by Year of Release", x-axis = "Release year", y-axis = "Duration (min), and using the 'colors' list to color every datapoint.
import matplotlib.pyplot as plt
fig = plt.figure()
plt.scatter(data=netflix_movies ,x='release_year', y='duration', c=colors)
# The desired x and y axis labels are different so I input them manually.
plt.title('Movie Duration by Year of Release')
plt.xlabel('Release year')
plt.ylabel('Duration (min)')
plt.show()
Are we certain that movies are getting shorter?
CONCLUSION: We can see in the plot that movies in general are not getting shorter. More movies are being produced every year and the majority have an approximate duration of 100 minutes or longer. While some movie genres like 'Children', 'Documentaries' or 'Stand Up' (in yellow, blue, and orange respectively) seem to be getting shorter, other genres (in grey) have longer durations.