text_html_output_1.png application_vnd.jupyter.stderr_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

df = pd.read_csv('../input/youtube-new/USvideos.csv')

cnt_video_per_category = df.groupby(["category_id"]).count().reset_index()
cnt_video_per_category = cnt_video_per_category.loc[:,['category_id','video_id']]
df_1 = pd.merge(cnt_video_per_category,category_df,left_on='category_id',right_on='category_id',how='left')
df_1 = df_1.sort_values(by='video_id', ascending = False)
df_1["Proportion"] = round((df_1["video_id"]/sum(df_1["video_id"]) * 100),2)
print(df_1)

sns.set(style="whitegrid")
plt.figure(figsize=(11, 10))
ax = sns.barplot(x="category_name",y="video_id", data=df_1)
ax.set_xticklabels(ax.get_xticklabels(), rotation=40, ha="right")
plt.tight_layout()
plt.show()

df['likes_rate'] = df['likes'] / df['views'] * 100
df['dislikes_rate'] = df['dislikes'] / df['views'] * 100
df['comment_rate'] = df['comment_count'] / df['views'] * 100
cnt_likes_per_video_per_category = df.groupby('category_id').mean().reset_index()
cnt_likes_per_video_per_category = cnt_likes_per_video_per_category.loc[:, ['category_id', 'likes_rate', 'dislikes_rate', 'comment_rate']]
df_2 = pd.merge(cnt_likes_per_video_per_category, category_df, left_on='category_id', right_on='category_id', how='left')
print(df_2)
df_2 = df_2.sort_values(by='likes_rate', ascending=False)
sns.set(style='whitegrid')
plt.figure(figsize=(11, 10))
plt.title('likes rate')
ax = sns.barplot(x='category_name', y='likes_rate', data=df_2)
ax.set_xticklabels(ax.get_xticklabels(), rotation=40, ha='right')
plt.tight_layout()
plt.show()
df_2 = df_2.sort_values(by='dislikes_rate', ascending=False)
sns.set(style='whitegrid')
plt.figure(figsize=(11, 10))
plt.title('dislikes rate')
ax = sns.barplot(x='category_name', y='dislikes_rate', data=df_2)
ax.set_xticklabels(ax.get_xticklabels(), rotation=40, ha='right')
plt.tight_layout()
plt.show()
df_2 = df_2.sort_values(by='comment_rate', ascending=False)
sns.set(style='whitegrid')
plt.figure(figsize=(11, 10))
plt.title('comments rate')
ax = sns.barplot(x='category_name', y='comment_rate', data=df_2)
ax.set_xticklabels(ax.get_xticklabels(), rotation=40, ha='right')
plt.tight_layout()
plt.show()