UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc9 in position 388: invalid continuation byte

*爱你&永不变心* 提交于 2021-02-10 06:36:35

问题


I am really beginning at python, but I am hours in this line, can't go anywhere without fixing it.

cadastro_2019_10= pd.read_csv("inf_cadastral_fi_20191015.csv",delimiter=";")[["CNPJ_FUNDO","DENOM_SOCIAL","CLASSE"]]

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc9 in position 49: invalid continuation byte

cadastro_2019_10= pd.read_csv("inf_cadastral_fi_20191015.csv",delimiter=";")[["CNPJ_FUNDO","DENOM_SOCIAL","CLASSE"]]

again:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc9 in position 388: invalid continuation byte


回答1:


Figure out what encoding the CSV file uses. Seems it doesn't use UTF-8. Say it's latin1, then you can try with read_csv(..., encoding="latin1").

If you are on a UNIX system, you can use the file command to try to detect the encoding.




回答2:


I found that I had to add :encoding='cp1252' but thank you for your time



来源:https://stackoverflow.com/questions/58421078/unicodedecodeerror-utf-8-codec-cant-decode-byte-0xc9-in-position-388-invali

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