使用Pandas read_csv阅读CSV文件时出现parsers.pyx错误

iyr7buue  于 2022-12-09  发布在  其他
关注(0)|答案(2)|浏览(291)

我尝试将一个我拥有读写权限的csv文件读取到一个 Dataframe 中,使用Visual Code.Win10下的panda。我尝试的是:

df1 = pd.read_csv("C:\\Users\\me\\Desktop\\Python\\Analytics\\in\\test_DS.csv", sep=';', header = None)

df1 = pd.read_csv(r"C:\Users\me\Desktop\Python\Analytics\in\test_DS.csv", sep=';', header = None)

df1 = pd.read_csv(r"C:/Users/me/Desktop/Python/Analytics/in/test_DS.csv", sep=';', header = None)

但我还是得到了Error:无法打开parsers.pyxC:/Users/me/Desktop/Python/Pandas/_libs/parsers.pyx.中未找到文件
有谁能告诉我我做错了什么吗?

*******************回溯若要取得我实作的回溯:

except Exception:
        print("Exception in user code:")
        print("-"*60)
        traceback.print_exc(file=sys.stdout)
        print("-"*60)

我得到了:

Exception in user code:

------------------------------------------------------------

Traceback (most recent call last):
  File "pandas\_libs\parsers.pyx", line 1169, in pandas._libs.parsers.TextReader._convert_tokens
  File "pandas\_libs\parsers.pyx", line 1299, in pandas._libs.parsers.TextReader._convert_with_dtype
  File "pandas\_libs\parsers.pyx", line 1315, in pandas._libs.parsers.TextReader._string_convert
  File "pandas\_libs\parsers.pyx", line 1553, in pandas._libs.parsers._string_box_utf8
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in position 10: invalid start byte

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "c:\Users\me\Desktop\Python\GPTW-Analytics\py\main.py", line 22, in <module>
    df1 = pd.read_csv('C:/Users/me/Desktop/Python/GPTW-Analytics/in/test_DS.csv', sep=';')
  File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 702, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 435, in _read
    data = parser.read(nrows)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 1139, in read
    ret = self._engine.read(nrows)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 1995, in read
    data = self._reader.read(nrows)
  File "pandas\_libs\parsers.pyx", line 899, in pandas._libs.parsers.TextReader.read
  File "pandas\_libs\parsers.pyx", line 914, in pandas._libs.parsers.TextReader._read_low_memory
  File "pandas\_libs\parsers.pyx", line 991, in pandas._libs.parsers.TextReader._read_rows
  File "pandas\_libs\parsers.pyx", line 1123, in pandas._libs.parsers.TextReader._convert_column_data
  File "pandas\_libs\parsers.pyx", line 1176, in pandas._libs.parsers.TextReader._convert_tokens
  File "pandas\_libs\parsers.pyx", line 1299, in pandas._libs.parsers.TextReader._convert_with_dtype
  File "pandas\_libs\parsers.pyx", line 1315, in pandas._libs.parsers.TextReader._string_convert
  File "pandas\_libs\parsers.pyx", line 1553, in pandas._libs.parsers._string_box_utf8
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in position 10: invalid start byte
------------------------------------------------------------
dsf9zpds

dsf9zpds1#

我今天也遇到了同样的问题,重新安装Pandas和麻木没有帮助。修复了这个问题。值得检查吗?
此外,您的跟踪使文件看起来可能有损坏;也许还可以将文件的顶部张贴在此处以进行调试。

z3yyvxxp

z3yyvxxp2#

这是一个老问题,但如果有人像我一样在谷歌上搜索它。在我的情况下,这是一个编码问题-文件被打开为utf-8,虽然正确的编码是1251

相关问题