OneCompiler

ANNU

324

import pandas as pd
import matplotlib.pyplot as plt
df=pd.read_csv('INvideos.csv')
df
df.drop_duplicates(inplace=True)
df.dropna(inplace=True)
total_views=df['views'].sum()
total_likes=df['likes'].sum()
total_dislikes=df['dislikes'].sum()
total_comments=df['comment_count'].sum()

print("Total Views :",total_views)
print("Total Likes :",total_likes)
print("Total Dislikes :",total_dislikes)
print("Total Comments :",total_comments)
least_liked_video=df.loc[df['likes'].idxmin()]
top_liked_video=df.loc[df['likes'].idxmax()]
least_commented_video=df.loc[df['comment_count'].idxmin()]
top_commented_video=df.loc[df['comment_count'].idxmax()]
print("\n Least Liked Video : \n",least_liked_video[['title','likes']])
print("\n Top Liked Video : \n",top_liked_video[['title','likes']])
print("\n Least Commented Video : \n",least_commented_video[['title','likes']])
print("\n Top Commented Video : \n",top_commented_video[['title','likes']])
df['trending_date']=pd.to_datetime(df['trending_date'],format ='%y.%d.%m')
df['year']=df['trending_date'].dt.year
yearly_views=df.groupby('year')['views'].sum()
df['trending_date']
plt.bar(yearly_views.index,yearly_views.values)
plt.xlabel('Year')
plt.ylabel('Total Views')
plt.title('Year wise Total Views')
plt.xticks(yearly_views.index)
plt.show()
reacted_viewers=df[['likes','dislikes']]
reacted_viewers.plot(kind='bar',stacked=True)
plt.xlabel('Video Index')
plt.ylabel('Number of Views')
plt.title('Viewers who reacted on videos')
plt.show()