The sentiment analysis of the tweets and plot the results.
Wed Jun 19 2024 14:49:06 GMT+0000 (Coordinated Universal Time)
Saved by
@EbadulHaque
#python
# Perform sentiment analysis on the tweets and plot the results
from textblob import TextBlob
import matplotlib.pyplot as plt
import seaborn as sns
# Function to get the sentiment polarity
def get_sentiment(text):
return TextBlob(text).sentiment.polarity
# Apply the function to the tweet column
df['sentiment'] = df['tweet'].apply(get_sentiment)
# Plot the sentiment distribution
plt.figure(figsize=(10, 6))
sns.histplot(df['sentiment'], bins=30, kde=True)
plt.title('Sentiment Distribution of Tweets')
plt.xlabel('Sentiment Polarity')
plt.ylabel('Frequency')
plt.show()
print('Sentiment analysis and plot completed.')
content_copyCOPY
The sentiment analysis of the tweets has been completed, and the sentiment distribution plot is shown above
Comments