pandas read_csv error when loading CSV file [已关闭]

falq053o  于 2023-11-14  发布在  其他
关注(0)|答案(1)|浏览(157)

**已关闭。**此问题是not reproducible or was caused by typos。目前不接受答案。

这个问题是由一个错字或一个无法再重现的问题引起的。虽然类似的问题可能在这里是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
11天前关闭
Improve this question
我想用Python打开一个简单的CSV文件(记事本文件),名为'123123'

hello,hallo,hoihoi
123,123,123
34,34,46

字符串
我想用下面的代码运行它:
进口Pandas作PD

data = pd.read_csv(r'\C:\Users\Jette\Documents\pythonProject\123123.csv', engine="python", sep=',', encoding='latin-1')


然而,我一直得到以下错误。

C:\Users\Jette\Documents\pythonProject\venv\Scripts\python.exe C:\Users\Jette\Documents\pythonProject\main.py 
Traceback (most recent call last):
  File "C:\Users\Jette\Documents\pythonProject\main.py", line 11, in <module>
    data = pd.read_csv(r'\C:\Users\Jette\Documents\pythonProject\123123.csv', engine="python", sep=',', encoding='latin-1')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\pandas\io\parsers\readers.py", line 948, in read_csv
    return _read(filepath_or_buffer, kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\pandas\io\parsers\readers.py", line 611, in _read
    parser = TextFileReader(filepath_or_buffer, **kwds)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\pandas\io\parsers\readers.py", line 1448, in __init__
    self._engine = self._make_engine(f, self.engine)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\pandas\io\parsers\readers.py", line 1705, in _make_engine
    self.handles = get_handle(
                   ^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\pandas\io\common.py", line 863, in get_handle
    handle = open(
             ^^^^^
OSError: [Errno 22] Invalid argument: '\\C:\\Users\\Jette\\Documents\\pythonProject\\123123.csv'

Process finished with exit code 1


我可以在网上找到类似的问题和答案,但它们对我不起作用。有人能帮助我吗?提前谢谢你。

z4bn682m

z4bn682m1#

看起来你有无效的路径。请尝试按以下方法操作:

data = pd.read_csv(r'C:\Users\Jette\Documents\pythonProject\123123.csv', engine="python", sep=',', encoding='latin-1')

字符串

相关问题