Skip to content
Project: Investigating Netflix Movies (definitely increase 25 %)
  • AI Chat
  • Code
  • Report
  • 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. Our friend has also been brushing up on their Python skills and has taken a first crack at a CSV file containing Netflix data. They believe that the average duration of movies has been declining. Using your friends initial research, you'll delve into the Netflix data to see if you can determine whether movie lengths are actually getting shorter and explain some of the contributing factors, if any.

    You have been supplied with the dataset netflix_data.csv , along with the following table detailing the column names and descriptions:

    The data

    netflix_data.csv

    ColumnDescription
    show_idThe ID of the show
    typeType of show
    titleTitle of the show
    directorDirector of the show
    castCast of the show
    countryCountry of origin
    date_addedDate added to Netflix
    release_yearYear of Netflix release
    durationDuration of the show in minutes
    descriptionDescription of the show
    genreShow genre
    # Importing pandas and matplotlib
    import pandas as pd
    import matplotlib.pyplot as plt
    
    #load a csv file with data
    netflix_df=pd.read_csv('netflix_data.csv')
    print(netflix_df.info())
    # filter data to be only Movies not TV-Shows
    netflix_subset=netflix_df[netflix_df['type']=='Movie']
    print(netflix_subset.info())
    
    netflix_movies=pd.DataFrame(netflix_subset[['title','country','genre','release_year',
                                               'duration']])
    print(netflix_movies.info())
    print(netflix_movies.head())
    # Filter DataFrame by Movie duration
    short_movies=netflix_movies[netflix_movies['duration']<60]
    print(short_movies.info())
    print(short_movies.head())
    netflix_movies_year=netflix_movies[netflix_movies['release_year']>=2000].groupby('release_year').count()['title']
    #Production of short movies through time
    short_movies_year=short_movies[short_movies['release_year']>=2000].groupby('release_year').count()['title']
    
    # I deaside to check what is ratio between total amoun of movies and short movies
    
    percent_of_short_movies=short_movies_year/netflix_movies_year
    
    # I drop two rows where we didnt have any value in data set, to make better visualisation
    percent_of_short_movies=percent_of_short_movies.drop(labels=[2002,2007],axis=0).reset_index()
    print(percent_of_short_movies)
    plt.plot(percent_of_short_movies.release_year,percent_of_short_movies.title)
    plt.title("Change in Production of Short Movies Netflix")
    plt.ylabel('Percent of Short Movies')
    plt.xlabel("Year")
    plt.show()

    How you can see we getting increase in production of short movies on Netflix

    # Let's look in what genres we get increas after 2015
    netflix_movies_2000=netflix_movies[netflix_movies['release_year']>=2015]
    table_total=pd.pivot_table(netflix_movies_2000,values='duration',index='genre',
                               columns='release_year',aggfunc='count',fill_value=0)
    short_movies_2000=short_movies[short_movies['release_year']>=2015]
    table_short=pd.pivot_table(short_movies_2000,values='duration',index='genre',
                               columns='release_year',aggfunc='count',fill_value=0)
    table_ratio=(table_short/table_total).round(3).fillna(0)
    table_ratio=table_ratio.drop(labels='Uncategorized',axis=0)
    print(table_ratio)

    We have stable increase in genres like: Children , Documentaries, Stand-up also we get and increas in Dramas for last few years

    ax = table_ratio.T.plot(kind='bar', ylabel='Year',xlabel='Percent from total by genre', figsize=(15,10))
    colors=[]
    for color,row in netflix_movies.iterrows():
        if row['genre']== "Children":
            colors.append('pink')
        elif row['genre'] == "Documentaries":
            colors.append('blue')
        elif row['genre']=="Stand-Up":
            colors.append('orange')
        else:
            colors.append('green')
    print(colors[:5])
        
    fig=plt.figure(figsize=(12,8))
    plt.scatter(netflix_movies.release_year,netflix_movies.duration,c=colors)
    plt.title("Movie Duration by Year of Release")
    plt.xlabel("Release year")
    plt.ylabel("Duration (min)")
    plt.show()
    answer='maybe'