Code Sample, a copy-pastable example if possible

# Your code here
import pandas
var=pandas.read_csv("C:\Script\testexp.csv")

Problem description

I am unable to read csv through python pandas. Kindly check code snippet, it's giving following error:

Traceback (most recent call last): File "", line 1, in File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 655, in parser_f return _read(filepath_or_buffer, kwds) File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 405, in _read parser = TextFileReader(filepath_or_buffer, kwds) File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 762, in init self._make_engine(self.engine) File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 966, in _make_engine self._engine = CParserWrapper(self.f, self.options) File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 1582, in init self._reader = parsers.TextReader(src, **kwds) File "pandas_libs\parsers.pyx", line 394, in pandas._libs.parsers.TextReader.cinit (pandas_libs\parsers.c:4209) File "pandas_libs\parsers.pyx", line 710, in pandas._libs.parsers.TextReader._setup_parser_source (pandas_libs\parse rs.c:8873) FileNotFoundError: File b'C:\Script\testexp.csv' does not exist

[this should explain why the current behaviour is a problem and why the expected output is a better solution.]

Expected Output

Output of pd.show_versions()

# Paste the output here pd.show_versions() here

Comment From: Ashutosh-Srivastav

File path is proper, their are read and write permissions provided on file..

Comment From: TomAugspurger

Can you try writing that as either "C:\\Script\\testexp.csv" or "C:/Script/testexp.csv". I think you need to escape your backslashes.

Comment From: jreback

or you can use r"C:\Script\testexp.csv"

@TomAugspurger maybe worthwile to put this in the doc-string / docs as this is a fairly common error?

Comment From: sarathprath

import pandas as pd
p=os.getcwd()
print(p)
df = pd.read_csv (r'C:\Users\vasud\PycharmProjects\pythonProject\Exam.csv')
print(df)

I have given the code as above and getting the below errors. Can someone help with this please? Am struck for quite a lot of time on this

Errors: Traceback (most recent call last): File "C:\Users\vasud\PycharmProjects\pythonProject\Assign.py", line 11, in df = pd.read_csv (r'Exam.csv') File "C:\Users\vasud\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\parsers.py", line 610, in read_csv return _read(filepath_or_buffer, kwds) File "C:\Users\vasud\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\parsers.py", line 462, in _read parser = TextFileReader(filepath_or_buffer, kwds) File "C:\Users\vasud\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\parsers.py", line 819, in init self._engine = self._make_engine(self.engine) File "C:\Users\vasud\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\parsers.py", line 1050, in _make_engine return mappingengine # type: ignore[call-arg] File "C:\Users\vasud\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\parsers.py", line 1898, in init self._reader = parsers.TextReader(self.handles.handle, kwds) File "pandas_libs\parsers.pyx", line 521, in pandas._libs.parsers.TextReader.cinit pandas.errors.EmptyDataError: No columns to parse from file