2
$\begingroup$

I have DataFrame which has column with spanish regions, when I import the .csv as following

df = pd.read_csv('...',delimiter=';',decimal=',')

And print the content of column, I see this: Castilla y Le�n.

I could not find a way how to fix it, but I am assuming there is smart way how to do it.

$\endgroup$
1
3
$\begingroup$

read_csv has an optional argument called encoding that deals with the way your characters are encoded.

You can give a try to:

df = pandas.read_csv('...', delimiter = ';', decimal = ',', encoding = 'utf-8')

Otherwise, you have to check how your characters are encoded (It is one of them).

You can read the doc of read_csv here

$\endgroup$
0
2
$\begingroup$

When using MacOs try this:

df.to_csv('file.csv', encoding='maccentraleurope')

From: Python Codecs

$\endgroup$
2
$\begingroup$

The solution was posted in Stack Overflow

You need:

df.to_csv('file.csv',encoding='utf-8-sig')
$\endgroup$
0
$\begingroup$

I have a Spanish dataframe and I use the latin-1 encoding.

df = pd.read_csv('...', delimiter = ';', decimal = ',', encoding = 'latin-1')
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.