Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't read csv using python pandas #16531

Closed
Ashutosh-Srivastav opened this issue May 29, 2017 · 4 comments
Closed

Can't read csv using python pandas #16531

Ashutosh-Srivastav opened this issue May 29, 2017 · 4 comments
Labels
IO CSV read_csv, to_csv Usage Question

Comments

@Ashutosh-Srivastav
Copy link

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
@Ashutosh-Srivastav
Copy link
Author

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

@TomAugspurger
Copy link
Contributor

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

@jreback
Copy link
Contributor

jreback commented May 29, 2017

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?

@jreback jreback closed this as completed May 29, 2017
@jreback jreback added IO CSV read_csv, to_csv Usage Question labels May 29, 2017
@jreback jreback added this to the No action milestone May 29, 2017
@sarathprath
Copy link

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 mapping[engine](self.f, **self.options) # 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO CSV read_csv, to_csv Usage Question
Projects
None yet
Development

No branches or pull requests

4 participants