Unicodedecorror when reading CSV file

Asked

Viewed 202 times

0

I am trying to read a CSV file in Python using:

import csv 
import json

arquivo = open('dados_teste.csv', encoding='utf8') 
texto = arquivo.read()
resultado = json.loads(texto)
print (resultado)

But you’re making that mistake:

Unicodedecodeerror: 'utf-8' codec can’t Decode byte 0x85 in position 78: invalid start byte

The lines start with text or special characters, I did not understand why only at position 78 he gives this error and in all before it not.

  • Could you ask the question about the folder organization you have? The file name is exactly teste or teste.csv?

  • If you have in windows, I think you have to 'test.csv'

  • Thanks @Andersoncarloswoss the error was pq forgot to put . csv in the same name. But now gave another error that did not understand the reason, I edited the question.

  • 1

    You are reading a file that does not have UTF-8 encoding as UTF-8. Check the encoding that was used when generating the file and also use it in reading.

  • Got it, thanks! This base is a tool that does not give me any options when exporting, neither format nor see the coding of it. any hint of how I can get this data directly from excel?

1 answer

0

There is no UTF-8 character that is or starts with 0X85. Its enconding does not match the encoding used in creating the file.

  • The original file is an xls, which I saved as csv with utf - 8 encoding, plus the original file is also with utf-8 encoding.

  • Which version of Excel are you using? Some older versions had problems with BOM.

  • I am using office 2016 package

Browser other questions tagged

You are not signed in. Login or sign up in order to post.