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")What was the most frequent movie duration in the 1990s?
To solve this, here is what we should do.
-
First, we need to find movies released in the 1990s:
- We create a filter that checks if the release year is between 1990 and 1999.
- This is done using the
np.logical_andfunction to combine two conditions: one for the year being greater than or equal to 1990, and another for the year being less than or equal to 1999.
-
Next, we filter for movies:
- We create another filter that checks if the type is 'Movie'.
-
Then, we combine these two filters:
- We use
np.logical_andagain to combine the filters for the 1990s and for movies. - This gives us a subset of the DataFrame that includes only movies released in the 1990s.
- We use
-
Now, we find the most common duration of these movies:
- We select the 'duration' column from this filtered DataFrame.
- We use the
.mode()function to find the most frequent value in this column. - We convert this value to an integer.
-
Finally, we print the result:
- We print a message that includes the most frequent movie duration in the 1990s.
import pandas as pd
import numpy as np
netflix_df = pd.read_csv("netflix_data.csv")
netflix_df
between_years = np.logical_and(1990 <= netflix_df['release_year'], netflix_df['release_year'] <= 1999)
movies = netflix_df['type'] == 'Movie'
duration = int(netflix_df[np.logical_and(between_years, movies)]['duration'].mode().values)
print('The most frequent movie duration in the 1990s was ' + str(duration) + ' minutes.')import pandas as pd
netflix_df = pd.read_csv("netflix_data.csv")
netflix_dfCount the number of short action movies released in the 1990s
To complete this request we will follow these steps.
-
First, we need to find movies released in the 1990s:
- We create a filter called
between_yearsthat checks if the release year is between 1990 and 1999. - This is done using the
np.logical_andfunction to combine two conditions: one for the year being greater than or equal to 1990, and another for the year being less than or equal to 1999.
- We create a filter called
-
Next, we filter for movies that are shorter than 90 minutes:
- We create another filter called
lengththat checks if the duration is less than 90 minutes. - We combine this with the
between_yearsfilter usingnp.logical_and.
- We create another filter called
-
Then, we filter for movies:
- We create a filter called
type_moviethat checks if the type is 'Movie'. - We combine this with the
lengthfilter usingnp.logical_and.
- We create a filter called
-
Now, we count the short action movies:
- We create a filter that checks if the genre is 'Action'.
- We apply this filter to the
type_moviefilter usingnp.logical_and. - We then count the number of titles that match this combined filter.
-
Finally, we print the result:
- We print a message that includes the count of short action movies released in the 1990s.
import pandas as pd
import numpy as np
netflix_df = pd.read_csv("netflix_data.csv")
netflix_df
between_years = np.logical_and(1990 <= netflix_df['release_year'], netflix_df['release_year'] <= 1999)
length = np.logical_and(between_years, netflix_df['duration'] < 90)
type_movie = np.logical_and(length, netflix_df['type'] == 'Movie')
short_movie_count = netflix_df[np.logical_and(type_movie, netflix_df['genre'] == 'Action')]['title'].count()
print('There were ' + str(short_movie_count) + ' short action movies released in the 1990s.')