CSV import by Pandas - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: CSV import by Pandas (/thread-26890.html) |
CSV import by Pandas - maryam88 - May-17-2020 I want to import a csv file by pd.read_csv and I put the file on site-pakages but python gives the error that the file doesn't exist, would uou please help me? The code and error are below: > a=pd.read_csv('sample') Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> a=pd.read_csv('sample') File "C:\Users\maryam\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\parsers.py", line 676, in parser_f return _read(filepath_or_buffer, kwds) File "C:\Users\maryam\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\parsers.py", line 448, in _read parser = TextFileReader(fp_or_buf, **kwds) File "C:\Users\maryam\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\parsers.py", line 880, in __init__ self._make_engine(self.engine) File "C:\Users\maryam\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\parsers.py", line 1114, in _make_engine self._engine = CParserWrapper(self.f, **self.options) File "C:\Users\maryam\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\parsers.py", line 1891, in __init__ self._reader = parsers.TextReader(src, **kwds) File "pandas\_libs\parsers.pyx", line 374, in pandas._libs.parsers.TextReader.__cinit__ File "pandas\_libs\parsers.pyx", line 674, in pandas._libs.parsers.TextReader._setup_parser_source FileNotFoundError: [Errno 2] File sample does not exist: 'sample' >>> RE: CSV import by Pandas - Axel_Erfurt - May-17-2020 The file does not exist in the working directory. Use the full path to the file.
RE: CSV import by Pandas - maryam88 - May-17-2020 Thank you but even when I use full path I get error RE: CSV import by Pandas - snippsat - May-17-2020 Remember on Windows is normal to use file name extensions on most files. So just sample is very uncommon,when sample.csv is not.# read_csv.py import pandas as pd df = pd.read_csv('sample.csv') print(df)So if read_csv.py and sample.csv is in same folder no Path is needed.Here use path to .csv file is placed. # read_csv.py import pandas as pd df = pd.read_csv(r'C:\code\sample.csv') print(df)Both yield no error and read the .csv file.
|