Python Central HubSign in

Data Analytics with Python / Phase 10: Data Analytics Projects

Netflix Movies & TV Shows Analysis

Clean and analyze Netflix catalog data - content types, countries, trends over years, and genre insights.

Goal

Analyze the Netflix titles dataset to answer:

  • Movies vs TV shows split
  • Top countries producing content
  • Content additions per year
  • Popular genres/categories

Analysis pipeline

diagram Netflix catalog pipeline mermaid
From raw titles to content trends by type, country, and year.

Common columns (Netflix titles dataset)

  • type (Movie/TV Show)
  • title, director, cast
  • country, date_added, release_year
  • rating, duration, listed_in

Step 1: Load and parse dates

Python
import pandas as pd
 
df = pd.read_csv("data/netflix_titles.csv")
 
if "date_added" in df.columns:
    df["date_added"] = pd.to_datetime(df["date_added"], errors="coerce")
 
print(df.shape)
print(df.head())

Step 2: Clean multi-valued country/genre

The dataset often stores multiple values separated by commas.

Python
# Countries
if "country" in df.columns:
    countries = (
        df.dropna(subset=["country"])
          .assign(country=df["country"].str.split(","))
          .explode("country")
    )
    countries["country"] = countries["country"].str.strip()
 
# Genres
if "listed_in" in df.columns:
    genres = (
        df.dropna(subset=["listed_in"])
          .assign(genre=df["listed_in"].str.split(","))
          .explode("genre")
    )
    genres["genre"] = genres["genre"].str.strip()

Step 3: Movies vs TV shows

Python
import seaborn as sns
import matplotlib.pyplot as plt
 
plt.figure(figsize=(6, 4))
sns.countplot(data=df, x="type")
plt.title("Movies vs TV Shows")
plt.tight_layout()
plt.show()

Step 4: Top countries

Python
import seaborn as sns
import matplotlib.pyplot as plt
 
if "country" in df.columns:
    top_c = countries["country"].value_counts().head(10).reset_index()
    top_c.columns = ["country", "count"]
 
    plt.figure(figsize=(10, 4))
    sns.barplot(data=top_c, x="count", y="country")
    plt.title("Top 10 countries by number of titles")
    plt.tight_layout()
    plt.show()

Step 5: Additions over time

Python
import matplotlib.pyplot as plt
 
if "date_added" in df.columns:
    yearly = df.dropna(subset=["date_added"]).groupby(df["date_added"].dt.year).size()
 
    plt.figure(figsize=(8, 4))
    plt.plot(yearly.index, yearly.values, marker="o")
    plt.title("Titles added by year")
    plt.xlabel("Year")
    plt.ylabel("Count")
    plt.tight_layout()
    plt.show()

Visualize it

sketch Movies vs TV Shows split p5.js
A donut chart makes the catalog mix obvious at a glance.

Deliverable

Summarize 5โ€“10 insights:

  • Which type dominates?
  • Which countries dominate?
  • Any clear growth periods?
  • Which genres show up most?

Check your understanding

quizCheck yourself
  1. Why use str.split(",") followed by explode() on country and listed_in?

    Show answer

    A โ€” One cell holds several comma-separated values, so each needs its own row to be counted correctly โ€” After exploding, value_counts counts one country or genre at a time.

  2. Why strip whitespace after exploding?

    Show answer

    A โ€” Values like " India" and "India" would otherwise be counted as different countries โ€” Splitting on commas leaves leading spaces in the pieces.

  3. How does the project compute titles added per year?

    Show answer

    A โ€” Group the non-null date_added values by its year and count rows โ€” It uses groupby(df["date_added"].dt.year).size() after dropping rows without a date.

  4. What does errors="coerce" do in pd.to_datetime for date_added?

    Show answer

    A โ€” Turns unparseable dates into NaT instead of raising โ€” Bad or missing dates become NaT, which are then dropped before grouping.

๐Ÿงช Try It Yourself

Exercise 1 โ€“ Split a multi-value column

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 2 โ€“ Explode into one row per value

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 3 โ€“ Titles added per year

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Was this page helpful?

Let us know how we did