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: Import your 'toolbox' ---
# We import the pandas library, which is the main tool for data analysis.
# We give it the nickname 'pd' to save time, which is the standard practice.
import pandas as pd
# --- Step 2: Load the data ---
# We use the pandas 'read_csv' tool to read our 'netflix_data.csv' file.
# We save this entire table in a variable called 'df' (which stands for DataFrame).
# This 'df' variable is now our main "filing cabinet" or spreadsheet.
df = pd.read_csv("netflix_data.csv")
# --- Step 3: Solve Task 1 (Find the most frequent 1990s movie duration) ---
# First, we create a new, smaller table called 'movies_1990s'.
# This is our "filter" pattern. We are selecting rows from 'df'
# that match our rules.
movies_1990s = df[
# Rule 1: The 'release_year' column must be greater than or equal to 1990
(df['release_year'] >= 1990) &
# We use '&' (AND) to connect our rules.
# Rule 2: The 'release_year' column must be less than or equal to 1999
(df['release_year'] <= 1999)
]
# Now, we work with our NEW 'movies_1990s' table.
# 1. We select *only* the 'duration' column.
# 2. We use the '.mode()' function to find the most common value.
# 3. .mode() gives us a list (in case of a tie), so we use [0] to get the first item.
# 4. We save this single number into the 'duration' variable.
duration = movies_1990s['duration'].mode()[0]
# --- Step 4: Solve Task 2 (Count short 1990s action movies) ---
# We create another new, filtered table.
# This time, we are filtering the main 'df' table with FOUR rules.
short_action_movies_1990s = df[
# Rule 1: The 'genre' column must be exactly 'Action'.
# We use '==' (double equals) to check if two things are equal.
(df['genre'] == 'Action') &
# Rule 2: The 'duration' column must be less than 90.
(df['duration'] < 90) &
# Rule 3: The 'release_year' must be 1990 or newer.
(df['release_year'] >= 1990) &
# Rule 4: The 'release_year' must be 1999 or older.
(df['release_year'] <= 1999)
]
# Finally, we use the built-in Python 'len()' function.
# 'len()' gets the length (or the total number of rows) of our new table.
# We save this count (which is an integer) into the 'short_movie_count' variable.
short_movie_count = len(short_action_movies_1990s)
# --- End of Project ---
# The DataCamp project will automatically check the final values stored in
# your 'duration' and 'short_movie_count' variables to pass the project.
# --- Displaying the Answers ---
# Now, we use the "loud" print() function to see what's in our variables
print("The most frequent 90s duration is:")
print(duration)
print("The number of short action movies from the 90s is:")
print(short_movie_count)# --- Imports needed for plotting ---
import matplotlib.pyplot as plt
# --- Visualization for Task 1 ---
print(f"The most frequent duration is: {duration} minutes")
# Create a figure (drawing canvas) and set its size
plt.figure(figsize=(10, 6))
# Plot a histogram of the 'duration' column from your 1990s data
plt.hist(movies_1990s['duration'], bins=20, edgecolor='black')
# Add a title (using an f-string to include your 'duration' variable)
plt.title(f'Distribution of Movie Durations in the 1990s (Mode: {duration} mins)')
# Label the x-axis and y-axis
plt.xlabel('Movie Duration (minutes)')
plt.ylabel('Number of Movies')
# Add a light grid for readability
plt.grid(axis='y', alpha=0.75)
# Display the plot
plt.show()# --- Imports needed for plotting ---
import matplotlib.pyplot as plt
# --- Visualization for Task 2 ---
# This part recalculates the genre counts, just to be safe
genre_counts_1990s = movies_1990s['genre'].value_counts().head(10)
print(f"The number of short action movies is: {short_movie_count}")
# Create a figure and set its size
plt.figure(figsize=(12, 7))
# Plot a bar chart of the top 10 genres
genre_counts_1990s.plot(kind='bar', color='skyblue', edgecolor='black')
# Add a title that includes your 'short_movie_count' variable
plt.title(f'Top 10 Movie Genres in the 1990s (Short Action Count: {short_movie_count})')
# Label the axes
plt.xlabel('Genre')
plt.ylabel('Number of Movies')
# Rotate the x-axis labels so they are readable
plt.xticks(rotation=45, ha='right')
# Adjust layout to prevent labels from being cut off
plt.tight_layout()
# Display the plot
plt.show()