I need your help as i tried every method but not able to perform sentiment analysis on my noun phrases, extracted from tweets in dataframe, using TextBlob. Also i think TextBlob.noun_phrases function is not producing the correct results. See for yourself in the image below. I am really new to Python, please help!!
So my code for extracting the Noun phrase from dataframe is:
from textblob import TextBlob
nltk.download('wordnet')
nltk.download('brown')
nltk.download('punkt')
def blob(text):
return TextBlob(text).noun_phrases
df['Noun_Phrases'] = df['Tweets'].apply(blob)
df
Next, my code for sentiment analysis is below, and i get the error as shown in below image:
def getsubjectivity(text):
return TextBlob(text).sentiment.subjectivity
df['Subjectivity'] = df['Noun_Phrases'].apply(getsubjectivity)
Error: TypeError: The text
argument passed to __init__(text)
must be a string, not <class 'textblob.blob.WordList'>
not sure about your objective. in your getsubjectivity
function the input need to be string, seems like you are feeding it a list.
if you make the below change, you will overcome the error.
def getsubjectivity(text):
text=''.join(text)
return TextBlob(text).sentiment.subjectivity
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.