DDR爱好者之家 Design By 杰米

1、问题

在使用Python中pandas读取csv文件时,由于文件编码格式出现以下问题:

Traceback (most recent call last):
 File "pandas\_libs\parsers.pyx", line 1134, in pandas._libs.parsers.TextReader._convert_tokens
 File "pandas\_libs\parsers.pyx", line 1240, in pandas._libs.parsers.TextReader._convert_with_dtype
 File "pandas\_libs\parsers.pyx", line 1256, in pandas._libs.parsers.TextReader._string_convert
 File "pandas\_libs\parsers.pyx", line 1494, in pandas._libs.parsers._string_box_utf8
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 19: invalid start byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
 File "E:\PyCharm 2017.3.4\helpers\pydev\pydevd.py", line 1668, in <module>
  main()
 File "E:\PyCharm 2017.3.4\helpers\pydev\pydevd.py", line 1662, in main
  globals = debugger.run(setup['file'], None, None, is_module)
 File "E:\PyCharm 2017.3.4\helpers\pydev\pydevd.py", line 1072, in run
  pydev_imports.execfile(file, globals, locals) # execute the script
 File "E:\PyCharm 2017.3.4\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
  exec(compile(contents+"\n", file, 'exec'), glob, loc)
 File "F:/OneDrive - emails.bjut.edu.cn/Program/Python/DCAE/test.py", line 18, in <module>
  load_phenotypes_ABIDE2_RfMRIMaps()
 File "F:/OneDrive - emails.bjut.edu.cn/Program/Python/DCAE\Data\load_data.py", line 109, in load_phenotypes_ABIDE2_RfMRIMaps
  pheno = pd.read_csv(pheno_path)
 File "E:\Python\Python35\lib\site-packages\pandas\io\parsers.py", line 678, in parser_f
  return _read(filepath_or_buffer, kwds)
 File "E:\Python\Python35\lib\site-packages\pandas\io\parsers.py", line 446, in _read
  data = parser.read(nrows)
 File "E:\Python\Python35\lib\site-packages\pandas\io\parsers.py", line 1036, in read
  ret = self._engine.read(nrows)
 File "E:\Python\Python35\lib\site-packages\pandas\io\parsers.py", line 1848, in read
  data = self._reader.read(nrows)
 File "pandas\_libs\parsers.pyx", line 876, in pandas._libs.parsers.TextReader.read
 File "pandas\_libs\parsers.pyx", line 891, in pandas._libs.parsers.TextReader._read_low_memory
 File "pandas\_libs\parsers.pyx", line 968, in pandas._libs.parsers.TextReader._read_rows
 File "pandas\_libs\parsers.pyx", line 1094, in pandas._libs.parsers.TextReader._convert_column_data
 File "pandas\_libs\parsers.pyx", line 1141, in pandas._libs.parsers.TextReader._convert_tokens
 File "pandas\_libs\parsers.pyx", line 1240, in pandas._libs.parsers.TextReader._convert_with_dtype
 File "pandas\_libs\parsers.pyx", line 1256, in pandas._libs.parsers.TextReader._string_convert
 File "pandas\_libs\parsers.pyx", line 1494, in pandas._libs.parsers._string_box_utf8
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 19: invalid start byte

我认为该问题是由于文件编码格式不是'utf-8'所导致的,因此,尝试将文件格式进行转换,转换方式如下:

首先使用txt文本打开文件,然后另存为,在右下角将编码改为‘UTF-8',点击保存即可

解决Python中pandas读取*.csv文件出现编码问题

总结

以上所述是小编给大家介绍的解决Python中pandas读取*.csv文件出现编码问题 ,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?