I am trying to run a few hundred Trip Advisor reviews through a Sentiment Analysis program (via textblob), so that it will read each review and provide a sentiment for it. The program already works in that you can type a sentence in and it will return the sentiment (i.e. positive, negative, neutral). I would like to run a excel document through the program without having to manually type in each review. Ideally, the program returns a sentiment on each review.....How do I do this?
This is the code I already have...
from textblob import TextBlob
import string
z = 10
poscounter = 0
negcounter = 0
neucounter = 0
totalsentences = 0
while z > 0:
y = input("Type your sentence ").lower()
y = y.translate(str.maketrans('', '', string.punctuation))
y1 = TextBlob(y)
sentCheck = y1.sentiment.polarity
if y == "stop":
print(f"Positive Sentiment: {(poscounter/totalsentences) * 100} %")
print(f"Negative Sentiment: {(negcounter/totalsentences) * 100} %")
print(f"Neutral Sentiment: {(neucounter/totalsentences) * 100} %")
exit()
xplitIt = y.split(" ")
for something in xplitIt:
if something == "crowded" or something == "busy" or something == "crowds" or something == "hate" or something == "hated":
print("negative")
sentCheck = -0.1
break
if sentCheck==0:
print("neutral")
neucounter+=1
elif sentCheck>0 and sentCheck <=1:
print("positive")
poscounter+=1
elif sentCheck == -0.1 or sentCheck < 0:
negcounter+=1
if sentCheck != -0.1:
print("negative")
totalsentences = totalsentences + 1