Pandas \将数据帧导出为csv时,xc9会突出显示

Pandas \将数据帧导出为csv时,xc9会突出显示,pandas,Pandas,Pandas的to_csv()方法在我的数据帧中的字符串包含\xc9重音符号时产生错误。你知道我该如何快速解决这个问题吗 谢谢 ---------------------------------------------------------------------------UnicodeEncodeError回溯(最近的呼叫 last)/Users/slegroux1/Projects/FeaturEmo/en_features.py in() 360打印“--无打印。缺少相应的功能。” 3

Pandas的
to_csv()
方法在我的数据帧中的字符串包含
\xc9
重音符号时产生错误。你知道我该如何快速解决这个问题吗

谢谢

---------------------------------------------------------------------------UnicodeEncodeError回溯(最近的呼叫 last)/Users/slegroux1/Projects/FeaturEmo/en_features.py in() 360打印“--无打印。缺少相应的功能。” 361如果name='main': -->362主要

/main()中的Users/slegroux1/Projects/FeaturEmo/en_features.py 40如果输出: 41嵌入() --->42 dict2frame(功能)。至_csv(输出) 43如果打印与否(目录或我的csv列表): 44绘图功能(功能)

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/pandas/core/frame.pyc 在to_csv中(self、path_或_buf、sep、na_rep、float_格式、cols、header、, 索引,索引标签,模式,nanRep,编码,引用,行终止符, chunksize,tupleize_cols,**kwds)1408
chunksize=chunksize,引擎=kwds.get(“引擎”),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自我保存() 973 974

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/pandas/core/format.pyc in_save(self)1076中断1077 ->1078 self._save_chunk(开始_i,结束_i)1079 1080 def_save_chunk(self,开始_i,结束_i):

/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/pandas/core/format.pyc 在(self,start),end(i)1094 ix= 数据索引到本机类型(切片器=切片器,na_rep=self.na_rep, float_格式=self.float_格式)1095 ->1096 lib.write_csv_行(self.data、ix、self.nlevels、self.cols、self.writer)1097 1098#从集合导入 命名双倍

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

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


您应该使用
encoding
参数指定编码,以
to_csv
。例如,
df.to_csv(filename,encoding='utf-8')