Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

pandas to_csv using latin script Ç as separator?

My team uses a Ç (ALT 0199) as a separator in their CSV files. I’m trying to replicate using this in Pandas, but not having any luck. Any guidance is appreciated as I’m new to Pandas

results.to_csv('filename.csv', encoding='latin1', sep='Ç')

SyntaxError: (unicode error) ‘utf-8’ can’t decode byte 0xc7

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The fact that you get a SyntaxError seems to indicate that Python can’t even read your program, let alone run it. It would seem that your Python source code file is encoded as iso-8859-1 (a.k.a latin-1), but Python thinks it’s in the default utf-8 encoding. Try adding a comment at the beginning of the file:

# -*- coding: iso-8859-1 -*-

See the Lexical Analysis chapter of the language reference for details.

Alternatively, avoid using "funny" characters in the source code, and do

results.to_csv(blabla, sep='\u00c7')

(And seriously, if you need to use funny separators in your "C"SV:s, then something, somewhere, isn’t using a proper CSV parser. Chaos awaits in your future…)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading