How to open . csv file containing "ç" in column label with Python

Asked

Viewed 175 times

0

I’m starting at the Python and I have a problem: I need to open a file .csv in the Python, but in the column header contains a ç.

When I try to open it presents the following error:

Unicodedecodeerror: 'utf-8' codec can’t Decode byte 0xe7 in position 17: invalid continuation byte

Below an excerpt from my code:

import pandas as pd

caminhoarquivo = r'C:\Users\user\Desktop\teste.csv'

basedados = pd.read_csv(caminhoarquivo,sep=';',decimal=',')

1 answer

0


Let’s see...

Your file CSV is most likely in a different coding of UTF-8. Generally this encoding can be Latin-1. If the file was created by you, it is easy to determine by checking the program that created it.

Solution

Modify the conversion encoding of read_csv. As an example, considering that Latin-1, change

basedados = pd.read_csv(caminhoarquivo, sep=';', decimal=',')

For

basedados = pd.read_csv(caminhoarquivo, sep=';', decimal=',', encoding='latin-1')

Browser other questions tagged

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