"""
# Netflix Shows and Movies - Exploratory Analysis¶
"""
"""
![pic.jfif](attachment:pic.jfif)
"""
"""
Netflix is an application that keeps growing bigger and faster with its popularity, shows and content. This is an EDA or a story telling through its data along with a wide range of different graphs and visuals.The dataset consists of meta details about the movies and tv shows such as the title, director, and cast of the shows / movies. Details such as the release year, the rating, duration etc. As the first step, let's load the dataset. In this kernel, I have analysed this dataset to find top insights and findings.

"""
import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt
import seaborn as sns
"""
### Loading the dataset
"""
netflix=pd.read_csv("../input/netflix-shows/netflix_titles.csv")
netflix.head(10)
netflix.info()
netflix.shape
"""
it is clear that the dataset contains 12 columns for exploratory analysis.
"""
netflix.count()
netflix.isnull().sum()
netflix_shows = netflix[netflix['type']=='TV Show']
netflix_movies = netflix[netflix['type']=='Movie']
"""
### Analysis of Movies vs TV Shows
"""
sns.set(style="darkgrid")
ax = sns.countplot(x="type", data=netflix, palette="Set2")
"""
It is evident that there are more Movies on Netflix than TV shows.
"""
old = netflix.sort_values("release_year", ascending=True)
old[['title','release_year']][:10]
"""
### If a producer wants to release some content, which month must he do so?
"""
netflix_date = netflix_shows[['date_added']].dropna()
netflix_date['year'] = netflix_date['date_added'].apply(lambda x : x.split(', ')[-1])
netflix_date['month'] = netflix_date['date_added'].apply(lambda x : x.lstrip().split(' ')[0])

month_order = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][::-1]
df = netflix_date.groupby('year')['month'].value_counts().unstack().fillna(0)[month_order].T
plt.figure(figsize=(10, 7), dpi=200)
plt.pcolor(df, cmap='afmhot_r', edgecolors='white', linewidths=2) # heatmap
plt.xticks(np.arange(0.5, len(df.columns), 1), df.columns, fontsize=7, fontfamily='serif')
plt.yticks(np.arange(0.5, len(df.index), 1), df.index, fontsize=7, fontfamily='serif')

plt.title('Netflix Contents Update', fontsize=12, fontfamily='calibri', fontweight='bold', position=(0.20, 1.0+0.02))
cbar = plt.colorbar()

cbar.ax.tick_params(labelsize=8) 
cbar.ax.minorticks_on()
plt.show()
"""
### Movie ratings analysis
"""
plt.figure(figsize=(25,10))
sns.set(style="darkgrid")
ax = sns.countplot(x="rating", data=netflix_movies, palette="Set2", order=netflix_movies['rating'].value_counts().index[0:15])
"""
The largest count of movies are made with the 'TV-MA' rating."TV-MA" is a rating assigned by the TV Parental Guidelines to a television program that was designed for mature audiences only.

Second largest is the 'TV-14' stands for content that may be inappropriate for children younger than 14 years of age.

Third largest is the very popular 'R' rating.An R-rated film is a film that has been assessed as having material which may be unsuitable for children under the age of 17 by the Motion Picture Association of America; the MPAA writes "Under 17 requires accompanying parent or adult guardian".
"""
country_count=netflix['country'].value_counts().sort_values(ascending=False)
country_count=pd.DataFrame(country_count)
topcountries=country_count[0:10]
topcountries
import plotly.express as px 
data = dict(
    number=[2818,972,419,245,199,181,145,124,110,106,105],
    country=["United States", "India", "United Kingdom", "Japan", "South Korea",'Canada','Spain','France','Mexico','Egypt','Turkey'])
fig = px.funnel(data, x='number', y='country')
fig.show()
"""
### Year wise analysis
"""
plt.figure(figsize = (35,8))
sns.countplot(x='release_year',data = netflix)
"""
As we can see most of the Movies and Tv shows on Netflix are Released in the past decade and very few were released earlier
"""
plt.figure(figsize=(12,10))
sns.set(style="darkgrid")
ax = sns.countplot(y="release_year", data=netflix_movies, palette="Set2", order=netflix_movies['release_year'].value_counts().index[0:10])
"""
So, 2017 and 2018 were the years when most of the movies were released.
"""
plt.figure(figsize=(15,10))
sns.set(style="darkgrid")
ax = sns.countplot(y="director", data=netflix_movies, palette="deep", order=netflix_movies['director'].value_counts(ascending = False).index[0:10])
"""
1.'Raúl Campos & Jan Suter' directed the most programs on Netflix.

2.More than half of the top10 most frequent directors are American directors.
"""
plt.figure(figsize=(12,6))
netflix[netflix["type"]=="Movie"]["listed_in"].value_counts(sort = True)[:10].plot(kind="barh",color="black")
plt.title("Top 10 Genres of Movies", size=18)
plt.figure(figsize=(12,6))
netflix[netflix["type"]=="TV Show"]["listed_in"].value_counts()[:10].plot(kind="barh",color="brown")
plt.title("Top 10 Genres of TV Shows",size=18)
from wordcloud import WordCloud
plt.subplots(figsize=(25,15))
wordcloud = WordCloud(
                          background_color='Black',
                          width=1920,
                          height=1080
                         ).generate(" ".join(netflix.title))
plt.imshow(wordcloud)
plt.axis('off')
plt.savefig('cast.png')
plt.show()