text = str(text.encode('utf-8')) AttributeError: 'float' object has no attribute 'enc - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: text = str(text.encode('utf-8')) AttributeError: 'float' object has no attribute 'enc (/thread-4219.html) |
text = str(text.encode('utf-8')) AttributeError: 'float' object has no attribute 'enc - ulrich48155 - Jul-31-2017 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: 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') RE: text = str(text.encode('utf-8')) AttributeError: 'float' object has no attribute 'enc - buran - Jul-31-2017 Please, post the full traceback, not just the last line, in error tags. Also post your full code if you have not done so (the code in thread title is not seen in your code snippet) cross-posted at reddit 7 days ago https://www.reddit.com/r/learnpython/comments/6p1ihf/text_strtextencodeutf8_attributeerror_float/ RE: text = str(text.encode('utf-8')) AttributeError: 'float' object has no attribute 'enc - ulrich48155 - Jul-31-2017 Here is the full error message. The line from the title is part from this message.
|