Jul-31-2017, 05:15 AM
Im trying to do a sentiment analysis of Twitter tweets on different topics. Thereby, some topics produce the following error message:
AttributeError: 'float' object has no attribute 'encode'
What shall I do?
My code looks like this:
AttributeError: 'float' object has no attribute 'encode'
What shall I do?
My code looks like this:
import pandas as pd import numpy as np from nltk.sentiment.vader import SentimentIntensityAnalyzer tweets=pd.read_excel('Topic1.xlsx',header=0) sid = SentimentIntensityAnalyzer() for sentence in tweets.Tweet: tweets['Sentiment'] = tweets['Tweet'].apply(lambda sentence: sid.polarity_scores(sentence)['compound']) tweets.to_excel('Topic1s.xlsx')