HEMU
import pandas as pd
from nltk.tokenize import word_tokenize
from nltk.sentiment.vader import SentimentIntensityAnalyzer
import nltk
df=pd.read_csv('covid_2021_1.csv')
print(df.head())
df.dropna(inplace=True)
df['tokenized_comments']=df['comment_text'].apply(word_tokenize)
df['tokenized_comments']
def analyze_sentiment(comment):
analyzer=SentimentIntensityAnalyzer()
sentiment_scores=analyzer.polarity_scores(comment)
if sentiment_scores['compound']> 0 :
return 'postive'
elif sentiment_scores['compound'] < 0:
return 'negative'
else:
return 'neutral'
df['sentiment']=df['comment_text'].apply(analyze_sentiment)
df['sentiment']
sentiment_counts=df['sentiment'].value_counts(normalize=True)*100
print("\n Percentage of Comments By Sentiment : ")
print(sentiment_counts)