0% found this document useful (0 votes)
7 views7 pages

Chandru Lab 3

The document presents a social media analytics lab assignment focused on sentiment analysis, analyzing data from various platforms including Instagram, Twitter, and Facebook. It reveals that positive sentiments dominate user posts, with Instagram being the most popular platform, and highlights the importance of understanding user interactions and trending hashtags for marketing strategies. Additionally, a word cloud analysis emphasizes the contrast between positive and negative sentiments expressed by users.

Uploaded by

chandru.n2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

Chandru Lab 3

The document presents a social media analytics lab assignment focused on sentiment analysis, analyzing data from various platforms including Instagram, Twitter, and Facebook. It reveals that positive sentiments dominate user posts, with Instagram being the most popular platform, and highlights the importance of understanding user interactions and trending hashtags for marketing strategies. Additionally, a word cloud analysis emphasizes the contrast between positive and negative sentiments expressed by users.

Uploaded by

chandru.n2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

SOCIAL MEDIA ANALYTICS

LAB ASSIGNMENT-3

SENTIMENTAL ANALYSIS

SUBMITTED

CHANDRU N

(23MBA0001)

SUBMITTED TO
DR. BIJAY PRASAD KUSHWAHA
( PROFESSOR)

VIT BUSINESS SCHOOL


# Import Libraries For analysis and cleaning
import pandas as pd
import numpy as np
# for visaluatztion
import matplotlib.pyplot as plt
import seaborn as sns

#Access data file


df=pd.read_csv(r"C:\Users\HP\Desktop\sentimentdataset.csv")
df.head()

Unnamed: Unnamed:
Text Sentiment Timestamp User Platform Hashtags Retweets Likes Country Year M
0.1 0

Enjoying
a
beautiful 2023-01-15 #Nature
0 0 0 Positive User123 Twitter 15.0 30.0 USA 2023
day at 12:30:00 #Park
the park!
...

Traffic
was
terrible 2023-01-15 #Traffic
1 1 1 Negative CommuterX Twitter 5.0 10.0 Canada 2023
this 08:45:00 #Morning
morning.
...

Just
finished
an 2023-01-15 #Fitness
2 2 2 Positive FitnessFan Instagram 20.0 40.0 USA 2023
amazing 15:45:00 #Workout
workout!
...

Excited
about the
2023-01-15
3 3 3 upcoming Positive AdventureX Facebook #Travel 8.0 15.0 UK 2023
weekend 18:20:00 #Adventure
getaway!
...

Trying
out a new
2023-01-15 #Cooking
4 4 4 recipe for Neutral ChefCook Instagram 12.0 25.0 Australia 2023
dinner 19:55:00 #Food
tonight.
...

#Display number of rows and columns


df.shape

(732, 15)

# drop column Unnamed: 0.1


df.drop(columns='Unnamed: 0.1',inplace=True)
# Rename column Unnamed: 0 to id
df.rename(columns={'Unnamed: 0':'Id'},inplace=True)

#Checking blank cells


df.isnull().sum()

Id 0
Text 0
Sentiment 0
Timestamp 0
User 0
Platform 0
Hashtags 0
Retweets 0
Likes 0
Country 0
Year 0
Month 0
Day 0
Hour 0
dtype: int64

#Converting data in to strings


df['Text']= df['Text'].str.strip()
df['Sentiment']= df['Sentiment'].str.strip()
df['User']= df['User'].str.strip()
df['Platform']= df['Platform'].str.strip()
df['Hashtags']= df['Hashtags'].str.strip()
df['Country']= df['Country'].str.strip()

#Sentiment Analysis
df['Sentiment'].value_counts().nlargest(10).plot(kind='bar')
plt.title('Top 10 Sentiments based on Text')
plt.xlabel('Sentiment')
plt.ylabel('Count')
plt.show()

#Counting number of post from each platforms


df['Platform'].value_counts()

Platform
Instagram 258
Twitter 243
Facebook 231
Name: count, dtype: int64

#Creating Pie charts for post counts from each platforms


df['Platform'].value_counts().plot(kind='pie', autopct='%1.2f%%')
plt.title('Percentages of Platforms')
plt.legend()
plt.show()

#Analysing top hashtags


df['Hashtags'].value_counts().nlargest(10).plot(kind='bar')
plt.title('Top 10 Hashtags')
plt.xlabel('Hashtags')
plt.ylabel('Count')
plt.legend()
plt.show()

#platform top liked by users?¶


top_likes_platform = df.groupby('Platform')['Likes'].sum().nlargest(10)
top_likes_platform.plot(kind='bar')
plt.title('Top Platforms by Total Likes')
plt.xlabel('Platform')
plt.ylabel('Total Likes')
plt.show()
# Import required libraries
!pip install wordcloud
from wordcloud import WordCloud
import matplotlib.pyplot as plt

# Combine all text data into a single string


text_data = " ".join(df['Text'].dropna())

# Generate the word cloud


wordcloud = WordCloud(width=800, height=400, background_color='white', colormap='viridis', max_words=200).gener

# Plot the word cloud


plt.figure(figsize=(10, 5))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off') # Hide axes
plt.title("Word Cloud of Sentiment Texts", fontsize=14)
plt.show()

Requirement already satisfied: wordcloud in c:\users\hp\anaconda3\lib\site-packages (1.9.4)


Requirement already satisfied: numpy>=1.6.1 in c:\users\hp\anaconda3\lib\site-packages (from wordcloud) (1.24.3)
Requirement already satisfied: pillow in c:\users\hp\anaconda3\lib\site-packages (from wordcloud) (10.2.0)
Requirement already satisfied: matplotlib in c:\users\hp\anaconda3\lib\site-packages (from wordcloud) (3.8.0)
Requirement already satisfied: contourpy>=1.0.1 in c:\users\hp\anaconda3\lib\site-packages (from matplotlib->wor
dcloud) (1.2.0)
Requirement already satisfied: cycler>=0.10 in c:\users\hp\anaconda3\lib\site-packages (from matplotlib->wordclo
ud) (0.11.0)
Requirement already satisfied: fonttools>=4.22.0 in c:\users\hp\anaconda3\lib\site-packages (from matplotlib->wo
rdcloud) (4.25.0)
Requirement already satisfied: kiwisolver>=1.0.1 in c:\users\hp\anaconda3\lib\site-packages (from matplotlib->wo
rdcloud) (1.4.4)
Requirement already satisfied: packaging>=20.0 in c:\users\hp\anaconda3\lib\site-packages (from matplotlib->word
cloud) (24.1)
Requirement already satisfied: pyparsing>=2.3.1 in c:\users\hp\anaconda3\lib\site-packages (from matplotlib->wor
dcloud) (3.0.9)
Requirement already satisfied: python-dateutil>=2.7 in c:\users\hp\anaconda3\lib\site-packages (from matplotlib-
>wordcloud) (2.8.2)
Requirement already satisfied: six>=1.5 in c:\users\hp\anaconda3\lib\site-packages (from python-dateutil>=2.7->m
atplotlib->wordcloud) (1.16.0)
Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js
INFERENCE:

Users often share uplifting information, according to the sentiment analysis, which shows that
positive feelings predominate, followed by neutral and negative attitudes. Instagram is by far the
most popular social media network in this sample, with the most postings (258), followed by
Facebook (231), and Twitter (243). Likes and retweets, on the other hand, indicate varying amounts
of user interaction across platforms. Trending themes and user interests are highlighted by the top
ten hashtags, which may be useful for focused marketing campaigns. These findings are further
supported by a word cloud analysis, which shows that although terms like "traffic," "terrible," and
"frustrating" are frequently associated with negative attitudes, frequently used positive phrases like
"enjoying," "excited," and "amazing" are associated with negative sentiments. Traffic complaints
and everyday hardships account for the bulk of unfavourable opinions, pointing to areas that may
use better. Furthermore, different interaction patterns are shown by an examination of the most
popular platform, highlighting the need of comprehending audience behaviour. Deeper
understanding of how emotions change over time may be possible with a time-based sentiment
analysis, which would assist marketers and companies in modifying their approaches. These results
are extremely pertinent to brand engagement strategies, social media marketing, and consumer
sentiment monitoring, enabling companies to improve user experience and successfully handle
problem areas.

You might also like