Apr-14-2021, 06:50 AM
Hi,
I am new to python and strugling with a code, i know its been clearly thrown the error still i am failing to get it might anyone can help
I went online which i can overcome using Vader, still i am eager to know how to accomplish my logic.
Thanks in advance
I am new to python and strugling with a code, i know its been clearly thrown the error still i am failing to get it might anyone can help
from textblob import TextBlob sentence = input("Enter sentence:") def sentiment_analysis(inputSentence): def getSubjectivity(text): return TextBlob(text).sentiment.subjectivity #Create a function to get the polarity def getPolarity(text): return TextBlob(text).sentiment.polarity #Create two new columns ‘Subjectivity’ & ‘Polarity’ inputSentence ['TextBlob_Subjectivity'] = inputSentence['inputSentence'].apply(getSubjectivity) inputSentence ['TextBlob_Polarity'] = inputSentence['inputSentence'].apply(getPolarity) def getAnalysis(score): if score < 0: return 'Negative' elif score == 0: return 'Neutral' else: return 'Positive' inputSentence ['TextBlob_Analysis'] = inputSentence['TextBlob_Polarity'].apply(getAnalysis) return inputSentence sentiment_analysis(sentence)giving me following error:
Output:---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-21-5220518db4bc> in <module>
----> 1 sentiment_analysis(sentence)
<ipython-input-20-0d8612b5763c> in sentiment_analysis(inputSentence)
8
9 #Create two new columns ‘Subjectivity’ & ‘Polarity’
---> 10 inputSentence ['TextBlob_Subjectivity'] = inputSentence['inputSentence'].apply(getSubjectivity)
11 inputSentence ['TextBlob_Polarity'] = inputSentence['inputSentence'].apply(getPolarity)
12
TypeError: string indices must be integers
I want if user inputs a text, it should be populating with polarity and subjectivity along with text so i can do some analysis in it.I went online which i can overcome using Vader, still i am eager to know how to accomplish my logic.
Thanks in advance