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")
-- Here is the entire DataFrame as reference
SELECT *
FROM 'netflix_data.csv';
# Creates an empty list to store durations
dur = []
#Creates an zero value variable to count short movies
short_movie_count = 0
# Iteraties over DataFrame to retrieve 'duration' values for records with 'release_year' between 1990 and 1999 and adds them to the list 'dur'
for lab, row in netflix_df.iterrows():
if row.loc['release_year'] >= 1990 and row.loc['release_year'] < 2000:
dur.append(row.loc['duration'])
#Counts records with duration less than 90 where genre is 'Action' and type = 'Movie'
if row.loc['duration'] < 90 and row.loc['genre'] == 'Action' and row.loc['type'] == 'Movie':
short_movie_count += 1
# Calculate mode
duration = max(set(dur), key = dur.count)
print("The most frequent movie duration in the 1990s is: " + str(duration) + " minutes")
print(str(short_movie_count) + " movies under 90 minutes!")
This is the end of the assigned task given by DataCamp. I thought it would be interesting to see what other insights could be found from this data set. For this I will use a combination of Python and SQL depending on whoch i see as more appropriate.
- Top genres by decade ✓
- Average duration by genre
- Director with most titles
- Visualise the number of titles produced by each country
- Visualise the trend of TV shows vs. Movies released by year
- Top 10 most prolific actors on Netlix
# Top genres by decade
# Creates a list of each titles genre for each decade. This potentially could be tided up which I will be working on soon.
for lab, row in netflix_df.iterrows():
if row.loc['release_year'] >= 1940 and row.loc['release_year'] < 1950:
forties_genres = []
forties_genres.append(row.loc['genre'])
elif row.loc['release_year'] >= 1950 and row.loc['release_year'] < 1960:
fifties_genres = []
fifties_genres.append(row.loc['genre'])
elif row.loc['release_year'] >= 1960 and row.loc['release_year'] < 1970:
sixties_genres = []
sixties_genres.append(row.loc['genre'])
elif row.loc['release_year'] >= 1970 and row.loc['release_year'] < 1980:
seventies_genres = []
seventies_genres.append(row.loc['genre'])
elif row.loc['release_year'] >= 1980 and row.loc['release_year'] < 1990:
eighties_genres = []
eighties_genres.append(row.loc['genre'])
elif row.loc['release_year'] >= 1990 and row.loc['release_year'] < 2000:
nineties_genres = []
nineties_genres.append(row.loc['genre'])
elif row.loc['release_year'] >= 2000 and row.loc['release_year'] < 2010:
naughties_genres = []
naughties_genres.append(row.loc['genre'])
elif row.loc['release_year'] >= 2010 and row.loc['release_year'] < 2020:
tens_genres = []
tens_genres.append(row.loc['genre'])
else:
twenties_genres = []
twenties_genres.append(row.loc['genre'])
# Creates 3 lists, one which is a list of the previous lists created to iterate over. The second is a list of the decades. The third is empty and will be filled with the most popular genre in each decade.
decades = [forties_genres, fifties_genres, sixties_genres, seventies_genres, eighties_genres, nineties_genres, naughties_genres, tens_genres, twenties_genres]
most_pop_genre_dec = ['40s', '50s', '60s', '70s', '80s', '90s', '00s', '10s', '20s']
most_pop_genre_genre = []
# Iterates through decades list to find the most common genre for each decade and appends it to the emptry list.
for decade in decades:
decade_mode = max(set(decade), key=decade.count)
most_pop_genre_genre.append(decade_mode)
# Zips the two most_pop... lists to a dictionary
most_pop_genre = dict(zip(most_pop_genre_dec, most_pop_genre_genre))
# Iterates over dictionary to print the most popular genre per decade
for dec, gen in most_pop_genre.items():
print("The most popular genre in the " + dec + " is: " + gen)