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.
You work for a production company that specializes in nostalgic styles. You want to do some research on movies released in the 1990's. You'll delve into Netflix data and perform exploratory data analysis to better understand this awesome movie decade!
You have been supplied with the dataset netflix_data.csv, along with the following table detailing the column names and descriptions. Feel free to experiment further after submitting!
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 |
# Importing pandas and matplotlib
import pandas as pd
import matplotlib.pyplot as plt
# Read in the Netflix CSV as a DataFrame
netflix_df = pd.read_csv("netflix_data.csv")# Start coding here! Use as many cells as you like
import numpy as np
import seaborn as sns
import missingno as msno
# Setting up the visual aesthetics
%matplotlib inline
sns.set(style="whitegrid")
netflix_df.head()
netflix_df.info()
# Numerical columns
netflix_df.describe()
# Categorical columns
netflix_df.describe(include=['object'])# Visual representation
msno.matrix(netflix_df)
plt.show()
# Detailed count
missing_values = netflix_df.isnull().sum()
missing_values[missing_values > 0]# Convert 'date_added' to datetime
netflix_df['date_added'] = pd.to_datetime(netflix_df['date_added'], errors='coerce')
# Extract year from 'date_added' if needed
netflix_df['year_added'] = netflix_df['date_added'].dt.year
# Convert 'duration' to numeric (assuming duration is in minutes as per description)
netflix_df['duration'] = pd.to_numeric(netflix_df['duration'], errors='coerce')
# Verify changes
netflix_df.info()duplicates = netflix_df.duplicated().sum()
print(f"Number of duplicate rows: {duplicates}")
# Remove duplicates
netflix_df = netflix_df.drop_duplicates()plt.figure(figsize=(6,4))
sns.countplot(data=netflix_df, x='type', palette='viridis')
plt.title('Distribution of Show Types')
plt.xlabel('Type')
plt.ylabel('Count')
plt.show()# Since 'country' may have multiple countries separated by commas, we need to split them
countries = netflix_df['country'].dropna().str.split(', ').explode()
# Create a DataFrame with the counts of the top 10 countries
top_countries = countries.value_counts().head(10).reset_index()
top_countries.columns = ['Country', 'Number of Shows']
plt.figure(figsize=(12,6))
sns.barplot(data=top_countries, x='Country', y='Number of Shows', palette='plasma')
plt.title('Top 10 Countries by Number of Shows')
plt.xlabel('Country')
plt.ylabel('Number of Shows')
plt.xticks(rotation=45)
plt.show()plt.figure(figsize=(12,6))
sns.histplot(data=netflix_df, x='release_year', bins=30, kde=True, color='teal')
plt.title('Distribution of Release Years')
plt.xlabel('Release Year')
plt.ylabel('Number of Shows')
plt.show()plt.figure(figsize=(12,6))
sns.histplot(data=netflix_df, x='duration', bins=30, kde=True, color='coral')
plt.title('Distribution of Show Durations')
plt.xlabel('Duration (minutes)')
plt.ylabel('Number of Shows')
plt.show()
# If 'type' is either Movie or TV Show, we can compare durations
plt.figure(figsize=(12,6))
sns.boxplot(data=netflix_df, x='type', y='duration', palette='Set2')
plt.title('Duration by Show Type')
plt.xlabel('Type')
plt.ylabel('Duration (minutes)')
plt.show()# Assuming 'genre' may have multiple genres separated by commas
genres = netflix_df['genre'].dropna().str.split(', ').explode()
# Create a DataFrame with the counts of the top 15 genres
top_genres = genres.value_counts().head(15).reset_index()
top_genres.columns = ['genre', 'count']
plt.figure(figsize=(12,6))
sns.barplot(data=top_genres, x='genre', y='count', palette='magma')
plt.title('Top 15 Genres')
plt.xlabel('Genre')
plt.ylabel('Number of Shows')
plt.xticks(rotation=45)
plt.show()# Handle multiple directors if present
directors = netflix_df['director'].dropna().str.split(', ').explode()
# Create a DataFrame with the counts of the top 10 directors
top_directors = directors.value_counts().head(10).reset_index()
top_directors.columns = ['director', 'count']
plt.figure(figsize=(12,6))
sns.barplot(data=top_directors, x='director', y='count', palette='coolwarm')
plt.title('Top 10 Directors by Number of Shows')
plt.xlabel('Director')
plt.ylabel('Number of Shows')
plt.xticks(rotation=45)
plt.show()