Home > Mobile >  Python, Twitter Sentiment analysis
Python, Twitter Sentiment analysis

Time:11-20

i am getting this error upon running my code.

text = str(text.encode("utf-8")) AttributeError: 'float' object has no attribute 'encode'

I tried to convert my data into string using df['Translated_message']=df['Translated_message'].values.astype('string') but that doesnt worked.

CodePudding user response:

Text is a float. Check to cast as str before encoding.

CodePudding user response:

IIUC, use pandas.Series.str.encode :

df['Translated_message']=df['Translated_message'].astype(str).str.encode('utf-8')

In the same logic, you need to cast text as a string before calling str.encode:

text = str(text).encode('utf-8')
  • Related