将数据帧导出到csv时的\ xc9重音符号

时间:2014-01-13 01:57:36

标签: pandas

当我的数据框中的字符串包含to_csv()重音符时,Pandas'\xc9方法会产生错误。知道如何快速解决这个问题吗?

由于

  

----------------------------------------------- ---------------------------- UnicodeEncodeError Traceback(最近一次调用   最后)/Users/slegroux1/Projects/FeaturEmo/en_features.py in()       360打印“-----没有情节。缺少相应的功能。”       361如果名称 =='主要':    - > 362 main()

     main()中的      

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/pandas/core/frame.pyc   in_csv(self,path_or_buf,sep,na_rep,float_format,cols,header,   index,index_label,mode,nanRep,encoding,quoting,line_terminator,   chunksize,tupleize_cols,** kwds)1408
  chunksize = chunksize,engine = kwds.get(“engine”),1409
  tupleize_cols = tupleize_cols)    - > 1410 formatter.save()1411 1412 def to_excel(self,excel_writer,sheet_name ='sheet1',na_rep ='',

     

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/pandas/core/format.pyc   在保存(自我)       970       971否则:    - > 972 self._save()       973       974

     

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/pandas/core/format.pyc   在_save(自我)1076休息1077    - > 1078 self._save_chunk(start_i,end_i)1079 1080 def _save_chunk(self,start_i,end_i):

     

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/pandas/core/format.pyc   在_save_chunk中(self,start_i,end_i)1094 ix =   data_index.to_native_types(slicer = slicer,na_rep = self.na_rep,   float_format = self.float_format)1095    - > 1096 lib.write_csv_rows(self.data,ix,self.nlevels,self.cols,self.writer)1097 1098#from collections import   namedtuple

     

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/pandas/lib.so   在pandas.lib.write_csv_rows(pandas / lib.c:13871)()

     

UnicodeEncodeError:'ascii'编解码器无法对字符u'\ xc9'进行编码   位置0:序数不在范围内(128)

1 个答案:

答案 0 :(得分:1)

您应该使用encoding的{​​{1}}参数指定编码。例如,to_csv