Issue
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
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')
Answered By - krisstinkou
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.