Nadia Rizky Hairunnisa/

Project: Investigating Netflix Movies


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


show_idThe ID of the show
typeType of show
titleTitle of the show
directorDirector of the show
castCast of the show
countryCountry of origin
date_addedDate added to Netflix
release_yearYear of Netflix release
durationDuration of the show in minutes
descriptionDescription of the show
genreShow genre
# Importing pandas and matplotlib
import pandas as pd
import matplotlib.pyplot as plt

#Load Netflix dataset
netflix_df = pd.read_csv("netflix_data.csv")
#Filter 'type' column because we just want to investigate movies
value_to_keep = 'Movie'
netflix_subset = netflix_df.query('type == @value_to_keep')
#Keep only certain columns 
columns_to_keep = ['title', 'country', 'genre', 'release_year', 'duration']
netflix_movies = netflix_subset[columns_to_keep].copy()
#Filter movies that are shorter than 60 minutes
threshold_value = 60
short_movies = netflix_movies.query('duration < @threshold_value')
#Sort the dataframe by the release year to inspect whether movie duration changes over years
short_movies = short_movies.sort_values(by='release_year', ascending=True)
#Sort the dataframe by duration to inspect whether movie duration changes over years
short_movies = short_movies.sort_values(by='duration', ascending=True)

Are movies actually getting shorter in recent years? I have no idea :") It seems there's no specific pattern from both sorted dataframes. However, it's pretty challenging to inspect and draw conclusions from hundreds of rows just by a glance at the dataframe. So, let's jump into visualization instead; we might gain more valuable insights from it!

# Define an empty list for colors, and a list for custom color hex codes I want to use
colors = []
palette = ["#fc8d62", "#ffd92f", "#66c2a5", "#8da0cb"]

# Iterate over rows of netflix_movies, and assign colors according to genre groups as a list
for index, row in netflix_movies.iterrows():
    genre = row['genre']
    if genre == 'Children':
        colors.append(palette[0]) #red
    elif genre == 'Documentaries':
        colors.append(palette[1]) #yellow
    elif genre == 'Stand-Up':
        colors.append(palette[2]) #green
        colors.append(palette[3]) #lilac

# Set the figure style and initalize a new figure
fig = plt.figure(figsize=(10,10))

# Create a scatter plot of duration versus release_year
plt.scatter(netflix_movies['release_year'], netflix_movies['duration'], c=colors, alpha=0.3, s=15)

plt.xlabel("Release year", fontsize=12)
plt.ylabel("Duration (min)", fontsize=12)
plt.title("Movie Duration by Year of Release", fontsize=15)

As we see from the scatter plot, there's no strong correlation between the release year and duration, there are a lot of old movies with shorter duration and there are also a lot of recent movies with longer duration

answer = "no"
  • AI Chat
  • Code