Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

pandas

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

like image 615
costas Avatar asked Dec 18 '25 22:12

costas


2 Answers

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.

like image 87
csl Avatar answered Dec 21 '25 14:12

csl


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

like image 22
costas Avatar answered Dec 21 '25 14:12

costas