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()

#this section is used to check the likes, dislike, and comment rate

#first we need to create 3 new variable
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

#grouping the likes rate per category
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']]

#left join to get the category name
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)

#likes rate
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()

#dislikes rate
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()

#comments rate
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()

p_null = (len(df) - df.count()) * 100.0 / len(df)
p_null

train = df[['trending_date', 'title', 'channel_title', 'publish_time', 'tags', 'views', 'likes', 'dislikes', 'comment_count', 'video_error_or_removed']]
df.isnull().any()