Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when writing python pandas dataframe to csv file

I have a problem writing a Pandas dataframe to a csv file. I guess there are som characters that can not be translated but I do not know how to fix the problem. I need help on this.

Here is my simple call and the error message:

big_frame.to_csv('C:\DRO\test.csv')

error:

C:\Python27\lib\site-packages\pandas\lib.pyd in pandas.lib.write_csv_rows (pandas\lib.c:13528)()

UnicodeEncodeError: 'ascii' codec can't encode character u'\xd6' in position 1: ordinal not in range(128)
like image 648
jonas Avatar asked Jan 03 '14 16:01

jonas


1 Answers

Try using a different file encoding: big_frame.to_csv('C:\DRO\test.csv', encoding='utf-8')

like image 137
Paul H Avatar answered Oct 06 '22 01:10

Paul H