亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

解決Python中pandas讀取*.csv文件出現(xiàn)編碼問題

 更新時(shí)間:2019年07月12日 09:56:17   作者:倒影丶年華  
很多朋友在使用Python中pandas讀取csv文件時(shí),出現(xiàn)編碼格式問題,接下來(lái)通過(guò)本文給大家分享解決Python中pandas讀取*.csv文件出現(xiàn)編碼問題,需要的朋友可以參考下

1、問題

在使用Python中pandas讀取csv文件時(shí),由于文件編碼格式出現(xiàn)以下問題:

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

我認(rèn)為該問題是由于文件編碼格式不是'utf-8'所導(dǎo)致的,因此,嘗試將文件格式進(jìn)行轉(zhuǎn)換,轉(zhuǎn)換方式如下:

首先使用txt文本打開文件,然后另存為,在右下角將編碼改為‘UTF-8',點(diǎn)擊保存即可

總結(jié)

以上所述是小編給大家介紹的解決Python中pandas讀取*.csv文件出現(xiàn)編碼問題 ,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

  • Linux下Python安裝完成后使用pip命令的詳細(xì)教程

    Linux下Python安裝完成后使用pip命令的詳細(xì)教程

    這篇文章主要介紹了Linux下Python安裝完成后使用pip命令的詳細(xì)教程,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-11-11
  • Pandas中字符串和時(shí)間轉(zhuǎn)換與格式化的實(shí)現(xiàn)

    Pandas中字符串和時(shí)間轉(zhuǎn)換與格式化的實(shí)現(xiàn)

    本文主要介紹了Pandas中字符串和時(shí)間轉(zhuǎn)換與格式化的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-01-01
  • python3結(jié)合openpyxl庫(kù)實(shí)現(xiàn)excel操作的實(shí)例代碼

    python3結(jié)合openpyxl庫(kù)實(shí)現(xiàn)excel操作的實(shí)例代碼

    這篇文章主要介紹了python3結(jié)合openpyxl庫(kù)實(shí)現(xiàn)excel操作的實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-09-09
  • pandas的相關(guān)系數(shù)與協(xié)方差實(shí)例

    pandas的相關(guān)系數(shù)與協(xié)方差實(shí)例

    今天小編就為大家分享一篇pandas的相關(guān)系數(shù)與協(xié)方差實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-12-12
  • Python中的sys.stdout.write實(shí)現(xiàn)打印刷新功能

    Python中的sys.stdout.write實(shí)現(xiàn)打印刷新功能

    今天小編就為大家分享一篇Python中的sys.stdout.write實(shí)現(xiàn)打印刷新功能,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-02-02
  • python中的hashlib模塊使用實(shí)例

    python中的hashlib模塊使用實(shí)例

    這篇文章主要介紹了python中的hashlib模塊使用實(shí)例,hashlib是一個(gè)提供字符串加密功能的模塊,包含MD5和SHA的算法,MD5和SHA是摘要算法,文中以實(shí)例代碼講解hashlib模塊的基本用法,需要的朋友可以參考下
    2023-08-08
  • 詳談python3中用for循環(huán)刪除列表中元素的坑

    詳談python3中用for循環(huán)刪除列表中元素的坑

    下面小編就為大家分享一篇詳談python3中用for循環(huán)刪除列表中元素的坑,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-04-04
  • 基于Tensorflow的MNIST手寫數(shù)字識(shí)別分類

    基于Tensorflow的MNIST手寫數(shù)字識(shí)別分類

    這篇文章主要為大家詳細(xì)介紹了基于Tensorflow的MNIST手寫數(shù)字識(shí)別分類,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • 基于Python 優(yōu)化 MUI標(biāo)題欄

    基于Python 優(yōu)化 MUI標(biāo)題欄

    這篇文章主要介紹的是基于Python 優(yōu)化 MUI標(biāo)題欄,一個(gè)特色鮮明MUI界面無(wú)疑是能夠吸引用戶的關(guān)鍵之一,這利用css和JavaScript可以很快進(jìn)行實(shí)現(xiàn),但是同時(shí)對(duì)于初學(xué)者來(lái)說(shuō)也是困難的,下面文章就來(lái)學(xué)習(xí)幾個(gè)簡(jiǎn)單的小技巧實(shí)現(xiàn)頁(yè)面美化吧,需要的朋友可以參考一下
    2021-11-11
  • Python面向?qū)ο竽Хǚ椒ê蛦卫K代碼實(shí)例

    Python面向?qū)ο竽Хǚ椒ê蛦卫K代碼實(shí)例

    這篇文章主要介紹了Python面向?qū)ο竽Хǚ椒ê蛦卫K代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-03-03

最新評(píng)論