<jupyter_start><jupyter_text>Problem StatmentUse Netflix Movies and TV Shows dataset from Kaggle and perform following operations :- Make a visualization showing the total number of movies watched by children- Make a visualization showing the total number of standup comedies- Make a visualization showing most watched shows.- Make a visualization showing highest rated show- Make a dashboard containing all of these above visualizations.<jupyter_code>import numpy as np
import pandas as pd


import matplotlib.pyplot as plt
import seaborn as sns
from wordcloud import WordCloud

import re
df = pd.read_csv('netflix_titles.csv')
df.head()
df.info()
df.isnull().sum()
df.drop(index=df[df['date_added'].isnull()].index,inplace=True)
df.drop(index=df[df['rating'].isnull()].index,inplace=True)
df.drop(columns=['director','cast'],inplace=True)
df['country'] = df['country'].fillna(value=df['country'].mode()[0])
df.isnull().sum()
df['year_added'] = df['date_added'].apply(lambda x: x.split(' ')[-1])
df['year_added'] = pd.to_numeric(df['year_added'])
df['type'].value_counts()
df['rating'].value_counts()
target_audience = {
    'TV-PG': 'Kids',
    'TV-MA': 'Adults',
    'TV-Y7-FV': 'Kids',
    'TV-Y7': 'Kids',
    'TV-14': 'Teens',
    'R': 'Adults',
    'TV-Y': 'Kids',
    'NR': 'Adults',
    'PG-13': 'Teens',
    'TV-G': 'Kids',
    'PG': 'Kids',
    'G': 'Kids',
    'UR': 'Adults',
    'NC-17': 'Adults'
}
df['target_audience'] = df['rating'].apply(lambda x: target_audience.get(x))
df['target_audience'].head()
df['target_audience'].value_counts()
df['origin_country'] = df['country'].apply(lambda x: x.split(',')[0])
df['origin_country'].unique()
df.rename(columns={'listed_in':'genres'},inplace=True)
df['genres'].head(10)
df['genres'] = df['genres'].apply(lambda x: re.split(', | ,| & |,',x))
df['genres'].head(10)
df.info()
plt.figure(figsize=(5,5))
plt.pie(df['target_audience'].value_counts(),labels=['Adults','Teens','Kids'],colors=['#fcbe86','#95cf95','#8ebad9'],autopct='%.2f')
print(df['target_audience'].value_counts())
plt.figure(figsize=(5,5))
plt.pie(df[df['type']=='Movie']['target_audience'].value_counts(),labels=['Adults','Teens','Kids'],colors=['#fcbe86','#95cf95','#8ebad9'],autopct='%.2f')
print(df[df['type']=='Movie']['target_audience'].value_counts())
plt.title('Movies Audience Distribution')
plt.figure(figsize=(5,5))
plt.pie(df[df['type']=='TV Show']['target_audience'].value_counts(),labels=['Adults','Teens','Kids'],colors=['#fcbe86','#95cf95','#8ebad9'],autopct='%.2f')
print(df[df['type']=='TV Show']['target_audience'].value_counts())
plt.title('TV Shows Audience Distribution')
plt.figure(figsize=(15,7))
sns.histplot(data=df, x='rating',hue='target_audience',alpha=0.5)
plt.title('Content Ratings Histogram')
plt.figure(figsize=(16,8))
sns.scatterplot(x=df['release_year'],y=df['year_added'],hue=df['type'])
plt.title('Content Production')
plt.grid('on')
plt.figure(figsize=(5,5))
plt.pie(df['type'].value_counts(),labels=['Movies','TV Shows'],colors=['#fcbe86','#8ebad9'],autopct='%.2f')
print(df['type'].value_counts())
movie_genres_dict = {}
for i in df[df['type']=='Movie'].index:
    genres_list = df.loc[i]['genres']
    for genre in genres_list:
        genre=genre.lower()
        if movie_genres_dict.get(genre):
            movie_genres_dict[genre] = movie_genres_dict.get(genre) + 1
        else:
            movie_genres_dict[genre] = 1

movie_genres_df = pd.DataFrame(data={'genre':movie_genres_dict.keys(),'count':movie_genres_dict.values()})
movie_genres_df.head()
plt.figure(figsize=(10,10))
sns.barplot(data=movie_genres_df.sort_values(by='count',ascending=False),x='count',y='genre')
plt.title('Movie Genres')
tv_genres_dict = {}
for i in df[df['type']=='TV Show'].index:
    genres_list = df.loc[i]['genres']
    for genre in genres_list:
        genre=genre.lower()
        if tv_genres_dict.get(genre):
            tv_genres_dict[genre] = tv_genres_dict.get(genre) + 1
        else:
            tv_genres_dict[genre] = 1

tv_genres_df = pd.DataFrame(data={'genre':tv_genres_dict.keys(),'count':tv_genres_dict.values()})
tv_genres_df.head()
plt.figure(figsize=(10,10))
sns.barplot(data=tv_genres_df.sort_values(by='count',ascending=False),x='count',y='genre')
plt.title('TV Show Genres')
text = ""
for i in df.index:
    genres_list = df.loc[i]['genres']
    for genre in genres_list:
        genre=genre.lower()
        text += genre + ' '
        
wordcloud = WordCloud(background_color='white', width=1680, height=1680, max_words=150).generate(text)
plt.figure(figsize=(16,16))
plt.imshow(wordcloud)
plt.axis('off')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20824295010845986, 'fraction_numerical': 0.019522776572668113, 'mean_word_length': 6.449111470113086, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '372844', 'license': 'MIT', 'n_tokens_mistral': 1819, 'n_tokens_neox': 1730, 'n_words': 260, 'path': 'SEM5/A6/.ipynb_checkpoints/A6-checkpoint.ipynb', 'repo_name': 'Skywalker-19/DS_Honors', 'size': '4610'}