Skip to content

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. This data does contain null values and some outliers, but handling these is out of scope for the project. Feel free to experiment after submitting!

The data

netflix_data.csv

ColumnDescription
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
import numpy as np
import statistics as stat

# Start coding!
netflix_df = pd.read_csv("netflix_data.csv")
netflix_subset = netflix_df.loc[netflix_df["type"] == "Movie"]
netflix_movies = netflix_subset[["title", "country", "genre", "release_year","duration"]]
short_movies = netflix_movies.loc[netflix_movies["duration"] < 60]

colors = []
for genre in netflix_movies.genre:
    if genre == "Children":
        colors.append("green")
    elif genre == "Documentaries":
        colors.append("blue")
    elif genre == "Stand-Up":
        colors.append( "yellow")
    else:
        colors.append("red")


fig = plt.figure()
plt.scatter(netflix_movies.release_year, netflix_movies.duration, c=colors, alpha = 0.4)
plt.xlabel("Release year")
plt.ylabel("Duration (min)")
plt.title("Movie Duration by Year of Release")
plt.show()
for genre, frame in netflix_movies.groupby("genre"):
    if genre in ["Children", "Documentaries", "Stand-Up"]:
        tmp = frame.groupby("release_year")["duration"].mean()
        plt.plot(tmp.loc[2000:2020], label=genre.upper())
plt.xticks(range(2000,2021, 5))
plt.legend();
netflix_movies_mod = netflix_movies.copy()
netflix_movies_mod["duration"] = netflix_movies_mod["duration"].apply(lambda x: round(x, -1))
duration_stats = netflix_movies_mod.groupby("release_year")["duration"]
duration_stats.agg(stat.median).loc[2000:2020].plot(label="MODE")
max_diur = duration_stats.agg(max).loc[2000:2020]
max_diur.plot(label="MAX")
min_diur = duration_stats.agg(min).loc[2000:2020]
min_diur.plot(label="MIN")
plt.xlabel("Release Year")
plt.ylabel("duration (min)")
plt.title("Variability in Netflix Movie Durations Over Release Years")
plt.fill_between(range(2000,2021),
                 min_diur,
                 max_diur,
                 alpha=0.6
                )
plt.xticks(range(2000,2021, 5))
plt.grid()
plt.legend();
# Compute descriptive statistics
duration_stats = netflix_movies.loc[(netflix_movies.release_year >= 2000) & (netflix_movies.release_year < 2021)].groupby("release_year")["duration"].describe()[["25%", "50%", "75%"]]

# Plotting
duration_stats.plot()
plt.legend()
plt.fill_between(duration_stats.index,
                 duration_stats["25%"],
                 duration_stats["75%"],
                 alpha=0.6
                )
plt.xticks(range(2000,2021, 5))
plt.title("Distribution of Netflix Movie Durations Across Release Years")
plt.grid();
answer = "no"