Pandas: Can't read csv using python pandas

Created on 29 May 2017  ·  3Comments  ·  Source: pandas-dev/pandas

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:ProgramDataAnaconda3libsite-packagespandasioparsers.py", line 655, in parser_f
return _read(filepath_or_buffer, kwds)
File "C:ProgramDataAnaconda3libsite-packagespandasioparsers.py", line 405, in _read
parser = TextFileReader(filepath_or_buffer, *kwds)
File "C:ProgramDataAnaconda3libsite-packagespandasioparsers.py", line 762, in __init__
self._make_engine(self.engine)
File "C:ProgramDataAnaconda3libsite-packagespandasioparsers.py", line 966, in _make_engine
self._engine = CParserWrapper(self.f, *
self.options)
File "C:ProgramDataAnaconda3libsite-packagespandasioparsers.py", line 1582, in __init__
self._reader = parsers.TextReader(src, **kwds)
File "pandas_libsparsers.pyx", line 394, in pandas._libs.parsers.TextReader.__cinit__ (pandas_libsparsers.c:4209)
File "pandas_libsparsers.pyx", line 710, in pandas._libs.parsers.TextReader._setup_parser_source (pandas_libsparse
rs.c:8873)
FileNotFoundError: File b'C:\Scripttestexp.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

IO CSV Usage Question

Most helpful comment

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

All 3 comments

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

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

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

songololo picture songololo  ·  3Comments

nathanielatom picture nathanielatom  ·  3Comments

MatzeB picture MatzeB  ·  3Comments

matthiasroder picture matthiasroder  ·  3Comments

ericdf picture ericdf  ·  3Comments