OneCompiler

Ritzu

317

import pandas as pd
import matplotlib.pyplot as plt
from wordcloud import WordCloud
from collections import Counter
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
df=pd.read_csv('instagram_global_top_1000.csv')
df
top5=df[df['Audience Country']=='India'].nlargest(5,'Followers')
print("Top 5 Instagram Influencers from India")
sorted_top5=top5.sort_values(by='Followers',ascending=False)
print(sorted_top5[['Account','Followers']])
least_followers=df.nsmallest(1,'Followers')
print("\n Instagram account with least no of followers")
print(least_followers[['Account','Followers']])
categories=df['Category'].astype(str)
df['Category']
categories=df['Category'].astype(str)
word_tokens=categories.apply(lambda x: word_tokenize(str(x)))
word_tokens
stop_words=set(stopwords.words('english'))
filtered_text1 =[[word for word in tokens if word not in stop_words] for tokens in word_tokens]
filtered_text=' '.join(categories)
wordcloud=WordCloud().generate(filtered_text)
plt.figure(figsize=(10,5))
plt.imshow(wordcloud,interpolation='bilinear')
grouped_categories=df.groupby('Category').size().reset_index(name='counts')
print("\n Instagram Accounts Grouped by category")
print(grouped_categories)
plt.scatter(df['Followers'],df['Authentic engagement'])
plt.title('Relationship between Followers and Authentic Engegment')
plt.xlabel('Followers')
plt.ylabel('Authentic Engagement')
plt.show()
correlation=df['Followers'].corr(df['Authentic engagement'])
correlation