I'm using tweepy to capture some tweets in Portuguese and I'm saving these tweets in a csv file. All tweet text we're saved with special characters and now I can't convert then to the correct format.
My coding for the tweet capture is:
csvFile = open('ua.csv', 'a')
csvWriter = csv.writer(csvFile)
for tweet in tweepy.Cursor(api.user_timeline,id=usuario,count=10,
lang="en",
since="2018-12-01").items():
csvWriter.writerow([tweet.created_at, tweet.text.encode('utf-8')])
I'm reading the results like this:
test = pd.read_csv('ua.csv', header=None)
test.columns = ["date", "text"]
result = test['text'][0]
print(result)
'Aproveita essa promo\xc3\xa7\xc3\xa3o aqui!'
The result I need sholud be this:
print(result)
'Aproveita essa promoção aqui!'
I tried this code to convert:
print(result.decode('utf-8'))
and got this error message:
AttributeError: 'str' object has no attribute 'decode'
Where am I doing wrong ?
strnot abytesand you should probably specify the encoding the for the CSV writer as well.tweet.text.encode('utf-8')]i.e don't use.encode