UnicodeDecodeError Sentiment140 Kaggle

亡梦爱人 提交于 2020-05-13 14:32:08

问题


I am trying to read the Sentiment140.csv available on Kaggle: https://www.kaggle.com/kazanova/sentiment140

My code is this one:

import pandas as pd
import os

cols = ['sentiment','id','date','query_string','user','text']
BASE_DIR = ''
df = pd.read_csv(os.path.join(BASE_DIR, 'Sentiment140.csv'),header=None, names=cols)

And it gives me this error:

UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 80-81: invalid continuation byte

The things I would like to understand are:

1) How do I solve this issue?

2) Where can I see which type of encoding should I use instead of "utf-8", based on the error?

3) Using other encoding methods will cause me other issues later on?

Thanks in advance

P.s. I am using python3 on a mac


回答1:


This works: https://investigate.ai/investigating-sentiment-analysis/cleaning-the-sentiment140-data/

Turns out encoding="latin-1" and you have to specify column names, otherwise it will use the first row as column names. This is how lousy real-world dataset can be haha



来源:https://stackoverflow.com/questions/52016160/unicodedecodeerror-sentiment140-kaggle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!