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")Step 1. Filter for movies released in or after 1990
# Start coding here! Use as many cells as you like
# Subset the data to include only movies released in or after 1990
movies_after_1990 = netflix_df[
(netflix_df['type'] == 'Movie') & (netflix_df['release_year'] >= 1990)
]
# Further filter for movies released in or before 1999
# This ensures we are looking only at movies from the 1990s decade
movies_1990s = movies_after_1990[movies_after_1990['release_year'] <= 1999]
# Display a sample of the filtered dataset for verification
print("Sample of movies from the 1990s:")
print(movies_1990s.head())Step 2: Find the Most Frequent Movie Duration
# Visualize the distribution of movie durations for the 1990s
# Plot a histogram of the 'duration' column
plt.hist(movies_1990s['duration'], bins=15, edgecolor='black')
plt.title("Distribution of Movie Durations (1990s)")
plt.xlabel("Duration (minutes)")
plt.ylabel("Frequency")
plt.show()
# Determine the most frequent movie duration using mode
# Mode gives the most common value in the 'duration' column
most_frequent_duration = movies_1990s['duration'].mode()[0]
# Save the result as an integer
duration = int(most_frequent_duration)
# Print the most frequent movie duration
print(f"The most frequent movie duration in the 1990s: {duration} minutes")Step 3: Count the Number of Short Action Movies (< 90 Minutes)
# Filter the data for action movies
# Subset movies with the genre containing "Action"
# Using str.contains() to handle case insensitivity and null values
action_movies_1990s = movies_1990s[movies_1990s['genre'].str.contains('Action', case=False, na=False)]
# Initialize a counter to count short movies
# A movie is considered short if its duration is less than 90 minutes
short_movie_count = 0
# Iterate through the action movies DataFrame
# Use iterrows() to loop through rows of the DataFrame
for _, row in action_movies_1990s.iterrows():
# Check if the duration is less than 90 minutes
if row['duration'] < 90:
# Increment the counter for each short movie found
short_movie_count += 1
# Print the count of short action movies
print(f"The number of short action movies released in the 1990s: {short_movie_count}")