0% found this document useful (0 votes)
10 views3 pages

Sma10 A2

The document outlines an experiment aimed at developing social media text analytics models to enhance existing products or services. It includes code for uploading a dataset of reviews, performing sentiment analysis using the TextBlob library, and displaying the results. The experiment is part of a lab course for BE(AIML) students.

Uploaded by

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

Sma10 A2

The document outlines an experiment aimed at developing social media text analytics models to enhance existing products or services. It includes code for uploading a dataset of reviews, performing sentiment analysis using the TextBlob library, and displaying the results. The experiment is part of a lab course for BE(AIML) students.

Uploaded by

patelkrupa14904
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

EXPERIMENT NO : 10

Class: BE(AIML) Batch: A2 Sub:SMALAB

Aim:-
Develop social media text analytics models for improving existing product/ service

CODE:

!pip install pandas textblob matplotlib wordcloud

import pandas as pd
from textblob import TextBlob
import [Link] as plt
from wordcloud import WordCloud
from [Link] import files
import io # Import io for string processing

# Upload dataset
print("Upload [Link] file")
uploaded = [Link]()

# Get the file name


file_name = list([Link]())[0]

# Load dataset
# Fix for CSV parsing issue: remove outer quotes if present
content_bytes = uploaded[file_name]
content_string = content_bytes.decode('utf-8')

processed_lines = []
for line in content_string.splitlines():
processed_lines.append([Link]('"')) # Strip outer quotes
processed_content = '\n'.join(processed_lines)

df = pd.read_csv([Link](processed_content))

print("\nDataset Preview:")
display([Link]())

# ==========================================
# Sentiment Analysis Model
# ==========================================

def analyze_sentiment(text):
analysis = TextBlob(str(text))
polarity = [Link]

if polarity > 0:
return "Positive"
elif polarity < 0:
return "Negative"
else:
return "Neutral"

df["Sentiment"] = df["review"].apply(analyze_sentiment)

print("\nSentiment Results:")
display(df)

output:-

You might also like