<jupyter_start><jupyter_text>Entering  data into a dictionary<jupyter_code># Creating the years and durations lists
years = [2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020]
durations = [103, 101, 99, 100, 100, 95, 95, 96, 93, 90]

# Creating a dictionary with the two lists
movie_dict = {"years":years, "durations":durations}

# Printing the dictionary
movie_dict<jupyter_output><empty_output><jupyter_text>Creating a DataFrame from a dictionaryTo convert our dictionary movie_dict to a pandas DataFrame, we will first need to import the library under its usual alias.<jupyter_code># Importing pandas under its usual alias
import pandas as pd

# Creating a DataFrame from the dictionary
durations_df = pd.DataFrame(movie_dict)

# Printing the DataFrame
print(durations_df)<jupyter_output>years  durations
0   2011        103
1   2012        101
2   2013         99
3   2014        100
4   2015        100
5   2016         95
6   2017         95
7   2018         96
8   2019         93
9   2020         90<jupyter_text>A visual inspection of our data<jupyter_code># Importing matplotlib.pyplot under its usual alias and create a figure
import matplotlib.pyplot as plt

# Drawing a line plot of release_years and durations
plt.plot(durations_df["years"], durations_df["durations"])

# Creating a title
plt.title("Netflix Movie Durations 2011-2020")

# Showing the plot
plt.show()<jupyter_output><empty_output><jupyter_text>Loading the rest of the data from a CSV<jupyter_code>#  reading the CSV (attached in the same github page for reference) as a DataFrame
netflix_df = pd.read_csv("netflix_data.csv")

# to print the first five rows of the DataFrame
print(netflix_df.head(5))<jupyter_output>show_id     type  title           director  \
0      s1  TV Show     3%                NaN   
1      s2    Movie   7:19  <NAME>   
2      s3    Movie  23:59       <NAME>   
3      s4    Movie      9        <NAME>   
4      s5    Movie     21     <NAME>   

                                                cast        country  \
0  <NAME>, <NAME>, <NAME>, R...         Brazil   
1  <NAME>, <NAME>, <NAME>, ...         Mexico   
2  <NAME>, <NAME>, <NAME>, Lawrence ...      Singapore   
3  <NAME>, <NAME>, <NAME>...  United States   
4  <NAME>, <NAME>, <NAME>, Aar...  United States   

          date_added  release_year  duration  \
0    August 14, 2020          2020         4   
1  December 23, 2016          2016        93   
2  December 20, 2018          2011        78   
3  November 16, 2017          2009        80   
4    January 1, 2020          2008       123[...]<jupyter_text>Filtering for moviesBut there are lots of data which are irrelevant to our analysis so therfore we are going to create a new DataFrame "netflix_movies" altogether which will be containing only title, country, genre, release_year, and duration as columns for genre as Movie.<jupyter_code># subsetting the DataFrame for type "Movie"
netflix_df_movies_only = netflix_df[netflix_df["type"] == "Movie"]

# we here take out only the columns of interest such as title, country, genre and release_year
netflix_movies_col_subset = netflix_df_movies_only[["title", "country", "genre", "release_year", "duration"]]

# to print the first five rows of our new DataFrame "netflix_movies_col_subset"
print(netflix_movies_col_subset.head(5))<jupyter_output>title        country          genre  release_year  duration
1   7:19         Mexico         Dramas          2016        93
2  23:59      Singapore  Horror Movies          2011        78
3      9  United States         Action          2009        80
4     21  United States         Dramas          2008       123
6    122          Egypt  Horror Movies          2019        95<jupyter_text>Creating a scatter plotAs now we have got all the data for the analysis whether the Duration of the Movie has come down over the recent years or not.So now its time I will be creating a scatter plot with release year as x axis and duration on the y axis<jupyter_code># creating a figure and increasing its figure's size
fig = plt.figure(figsize=(12,8))

# plotting a scatter plot of duration versus year
plt.scatter(netflix_movies_col_subset["release_year"],netflix_movies_col_subset["duration"])

# for title
plt.title("Movie Duration by Year of Release")

# showing plot
plt.show()<jupyter_output><empty_output><jupyter_text>Something Different than expected, Right???Some of these films are much shorter than we expected it to be there. And to find out why is that then we will have to filter our DataFrame for movies with a duration which are under 60 minutes and will then look at the genres. This might give us some insight into what is dragging down the average.<jupyter_code># Filtering for durations shorter than 60 minutes
short_movies = netflix_movies_col_subset[netflix_movies_col_subset["duration"]<60]

# Printing the first 20 rows of short_movies
print(short_movies.head(20))<jupyter_output>title         country  \
35                                           #Rucker50   United States   
55                 100 Things to do Before High School   United States   
67   13TH: A Conversation with <NAME> & Ava ...             NaN   
101                                  3 Seconds Divorce          Canada   
146                                     A 3 Minute Hug          Mexico   
162  A Christmas Special: Miraculous: Tales of Lady...          France   
171                         A Family Reunion Christmas   United States   
177                    A Go! Go! <NAME> Christmas   United States   
178                    A Go! Go! <NAME>een             NaN   
179                  A Go! Go! <NAME> Summer Camp             NaN   
181             A Grand Night In: The Story of Aardman  United Kingdom   
200                            A Love Song for Latasha   United States   
220                         A Russell [...]<jupyter_text>To know if our there are any observations which may result in the wrong data analysisAs we see below that we have got quartiles, which may affect our data analysis and to we have to remove them from our data or ingnore them so that they dont affect our data anaylsis<jupyter_code>plt.boxplot(netflix_movies_col_subset["duration"])
plt.show()<jupyter_output><empty_output><jupyter_text>Marking non-feature films with Different colorsAbove we can figure out the fact that many of the films that are under 60 minutes fall into genres such as "Children", "Stand-Up", "Dramas" and "Documentaries". And this is perfectly logical, as these types of films are probably more than often shorter as compare to other Movies.Either we have to eliminate these rows from our DataFrame and plot the values again or we can continue to explore the effect of these genres on our data, but mark them with a different color.So we will make a list of colors based on the contents of the genre column and loop through them.<jupyter_code># creating an empty list which we will use to store (append) the results from looping
colors = []

# iterating over rows of our DataFrame "netflix_movies_col_subset"
for label, row in netflix_movies_col_subset.iterrows() :
    if row["genre"] == "Children" :
        colors.append("red")
    elif row["genre"] == "Documentaries" :
        colors.append("blue")
    elif row["genre"] == "Stand-Up" :
        colors.append("green")
    else:
        colors.append("black")

# just to check if we have done everything right by calling out the first 5 items of the list
print(colors[:5])<jupyter_output>['black', 'black', 'black', 'black', 'black']<jupyter_text>Plotting again the Scatter PlotBut this time with different colors for different genres of movies available in the Netflix Data. This will help us in differentiating how is different genres of movies affecting the duration of the shows over the years<jupyter_code># setting the figure style and initalizing a new figure
plt.style.use('fivethirtyeight')
fig = plt.figure(figsize=(12,8))

# plotting a scatter plot of duration versus release_year
plt.scatter(netflix_movies_col_subset["release_year"],netflix_movies_col_subset["duration"],c=colors)

# giving the graph a title and axis labels
plt.title("Movie duration by year of release")
plt.xlabel("Release year")
plt.ylabel("Duration (min)")

# to plot the graph
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06678722121760096, 'fraction_numerical': 0.04243520192887282, 'mean_word_length': 2.8550185873605947, 'pattern_counts': {'":': 2, '<': 60, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '612126', 'license': 'MIT', 'n_tokens_mistral': 2594, 'n_tokens_neox': 2290, 'n_words': 977, 'path': 'Netflix Exploratory Data Analysis/Exploratory Data Analysis (EDA).ipynb', 'repo_name': 'Gaurav1921/Data-Science-Projects', 'size': '8453'}