pandas 将python pandas数据帧写入csv文件时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20908786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error when writing python pandas dataframe to csv file
提问by jonas
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.
我在将 Pandas 数据帧写入 csv 文件时遇到问题。我猜有些字符无法翻译,但我不知道如何解决问题。我需要这方面的帮助。
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)
回答by Paul H
Try using a different file encoding:
big_frame.to_csv('C:\DRO\test.csv', encoding='utf-8')
尝试使用不同的文件编码:
big_frame.to_csv('C:\DRO\test.csv', encoding='utf-8')

