Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

pandas read_csv error when loading CSV file

I want to open a simple csv file (notepad file) using python, called ‘123123’

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

I want to run it using the following code;

import pandas as pd

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

However, I keep getting the following error.

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

I can find similar questions and answers online, but they do not work for me.
Can somebody help me?
Thank you in advance.

>Solution :

Looks like you have invalid path. Try do it as follows:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading