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

2024-10-01 10:20:42 发布

您现在位置:Python中文网/ 问答频道 /正文

--------------------------------------------------------------------------- UnicodeEncodeError Traceback (most recent call last) C:\Users\Deepayan\Desktop\Final_Dissertation\beauty-1.py in <module>() 71 print table 72 ---> 73 table.to_csv('fout2', mode='a', header=False) 74 75 fout2.close() C:\Users\Deepayan\AppData\Local\Enthought\Canopy\User\lib\site-packages\pandas\util\decorators.pyc in wrapper(*args, **kwargs) 86 else: 87 kwargs[new_arg_name] = new_arg_value ---> 88 return func(*args, **kwargs) 89 return wrapper 90 return _deprecate_kwarg C:\Users\Deepayan\AppData\Local\Enthought\Canopy\User\lib\site-packages\pandas\core\frame.pyc in to_csv(self, path_or_buf, sep, na_rep, float_format, columns, header, index, index_label, mode, encoding, quoting, quotechar, line_terminator, chunksize, tupleize_cols, date_format, doublequote, escapechar, **kwds) 1152 doublequote=doublequote, 1153 escapechar=escapechar) -> 1154 formatter.save() 1155 1156 if path_or_buf is None: C:\Users\Deepayan\AppData\Local\Enthought\Canopy\User\lib\site-packages\pandas\core\format.pyc in save(self) 1398 1399 else: -> 1400 self._save() 1401 1402 finally: C:\Users\Deepayan\AppData\Local\Enthought\Canopy\User\lib\site-packages\pandas\core\format.pyc in _save(self) 1498 break 1499 -> 1500 self._save_chunk(start_i, end_i) 1501 1502 def _save_chunk(self, start_i, end_i): C:\Users\Deepayan\AppData\Local\Enthought\Canopy\User\lib\site-packages\pandas\core\format.pyc in _save_chunk(self, start_i, end_i) 1520 date_format=self.date_format) 1521 -> 1522 lib.write_csv_rows(self.data, ix, self.nlevels, self.cols, self.writer) 1523 1524 # from collections import namedtuple C:\Users\Deepayan\AppData\Local\Enthought\Canopy\User\lib\site-packages\pandas\lib.pyd in pandas.lib.write_csv_rows (pandas\lib.c:16935)() UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 19: ordinal not in range(128)

我正试图将Python代码的输出导出到一个文件中,由于某些原因,我仍然面临“ascii”codec无法编码的问题。我试过很多次改动,但不知为什么,就是不起作用。在

^{pr2}$

Tags: inselfformatpandassavelibpackageslocal