Error - unable to read the csv file in pandas

after importing panda
i am unable to read the csv file

import pandas as pd
df=pd.read_csv(“data.csv”)

the error i am getting is :-


FileNotFoundError Traceback (most recent call last)
in ()
----> 1 df=pd.read_csv(“data.csv”)

~\Miniconda3\lib\site-packages\pandas\io\parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, doublequote, delim_whitespace, low_memory, memory_map, float_precision)
676 skip_blank_lines=skip_blank_lines)
677
–> 678 return _read(filepath_or_buffer, kwds)
679
680 parser_f.name = name

~\Miniconda3\lib\site-packages\pandas\io\parsers.py in _read(filepath_or_buffer, kwds)
438
439 # Create the parser.
–> 440 parser = TextFileReader(filepath_or_buffer, **kwds)
441
442 if chunksize or iterator:

~\Miniconda3\lib\site-packages\pandas\io\parsers.py in init(self, f, engine, **kwds)
785 self.options[‘has_index_names’] = kwds[‘has_index_names’]
786
–> 787 self._make_engine(self.engine)
788
789 def close(self):

~\Miniconda3\lib\site-packages\pandas\io\parsers.py in _make_engine(self, engine)
1012 def _make_engine(self, engine=‘c’):
1013 if engine == ‘c’:
-> 1014 self._engine = CParserWrapper(self.f, **self.options)
1015 else:
1016 if engine == ‘python’:

~\Miniconda3\lib\site-packages\pandas\io\parsers.py in init(self, src, **kwds)
1706 kwds[‘usecols’] = self.usecols
1707
-> 1708 self._reader = parsers.TextReader(src, **kwds)
1709
1710 passed_names = self.names is None

pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader.cinit()

pandas_libs\parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source()

FileNotFoundError: File b’data.csv’ does not exist

Hi Rishab,

Seems that pandas is not able to find the file, check if the file ‘data.csv’ is in same directory as the python script file. Or change the path to exact location of csv file …

Hi

You’ve to give the complete path of the file. For instance, if I save my file on desktop, I’d write it as :

df=pd.read_csv('/home/aishwarya/desktop/data.csv')
Similarly, find out the complete path of the file and change the command accordingly.

it helped thanks a lot :smiley:

Hi all,

I am facing the same issue. However, I am using the code as mentioned above but still the error of file not found is coming up. However, the file is present at this location. Let me know if you can catch the error. Thank you in advance.

The code I am using is:

#importing pandas library
import pandas as pd

#reading the csv file
Mean=pd.read_csv(’/Macintosh HD/⁨Users/sayantandutta⁩/⁨Desktop⁩/mean.csv’)

Error Message:

FileNotFoundError Traceback (most recent call last)
in
3
4 #reading the csv file
----> 5 Mean=pd.read_csv(’/Macintosh HD/⁨Users/sayantandutta⁩/⁨Desktop⁩/mean.csv’)

~/anaconda3/lib/python3.7/site-packages/pandas/io/parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision)
700 skip_blank_lines=skip_blank_lines)
701
–> 702 return _read(filepath_or_buffer, kwds)
703
704 parser_f.name = name

~/anaconda3/lib/python3.7/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds)
427
428 # Create the parser.
–> 429 parser = TextFileReader(filepath_or_buffer, **kwds)
430
431 if chunksize or iterator:

~/anaconda3/lib/python3.7/site-packages/pandas/io/parsers.py in init(self, f, engine, **kwds)
893 self.options[‘has_index_names’] = kwds[‘has_index_names’]
894
–> 895 self._make_engine(self.engine)
896
897 def close(self):

~/anaconda3/lib/python3.7/site-packages/pandas/io/parsers.py in _make_engine(self, engine)
1120 def _make_engine(self, engine=‘c’):
1121 if engine == ‘c’:
-> 1122 self._engine = CParserWrapper(self.f, **self.options)
1123 else:
1124 if engine == ‘python’:

~/anaconda3/lib/python3.7/site-packages/pandas/io/parsers.py in init(self, src, **kwds)
1851 kwds[‘usecols’] = self.usecols
1852
-> 1853 self._reader = parsers.TextReader(src, **kwds)
1854 self.unnamed_cols = self._reader.unnamed_cols
1855

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.cinit()

pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source()

FileNotFoundError: [Errno 2] File b’/Macintosh HD/\xe2\x81\xa8Users/sayantandutta\xe2\x81\xa9/\xe2\x81\xa8Desktop\xe2\x81\xa9/mean.csv’ does not exist: b’/Macintosh HD/\xe2\x81\xa8Users/sayantandutta\xe2\x81\xa9/\xe2\x81\xa8Desktop\xe2\x81\xa9/mean.csv’

Hi @anuradha68, I am sure that the file is on the desktop but could you check the location in the properties tab (right click the file and check properties). Just to confirm that we aren’t missing out anything.

Yes, I did that. A few months I used the same code to read the files and it worked but i dont know what is wrong with this piece of code.

@anuradha68, place a different csv file on your desktop and try to read that file. We will figure out if the problem is with the code block or the file.

Did that. Not working. The same is the case with excel file. it’s not able to read any file.

@anuradha68, then the code has some issue. Place the file in the same folder where you have the notebook. Then you can simply use the following code -

Mean=pd.read_csv(’mean.csv’)

Hy make sure there’s no space or anything after the csv extension.

hi , i’m really new this , i tried all the other options here but i am still having the same error .i would like to place the csv file in the same folder where i have the notebook to try it out but the problem is i don’t know how to locate that folder , please how do i locate it?

Hi,
Are you directly renaming the extension of a file to the .csv? if yes then it won’t work.

Like for the windows users, suppose user have an excel file which has the .xlsx extension and when the user directly rename the extension to the .csv after when user use it then it won’t work.

you needed to convert it into the .csv file. After that it will work.
I had also the same issue :P.

Thank you,

Hi,
if the path of the file is,
C:\Users\Owner\Downloads
so should the code be:
df=pd.read_csv(’/Users/Owners/Download/data.csv’)
or
df=pd.read_csv(’/C:/Users/Owners/Download/data.csv’)
or there has to be some other code?
because this is not working.
Please help. I am stuck over here for a long time.

thanks a lot it was really helpful

Just put ‘r’ in front of the path df=pd.read_csv(r’C:\Users\Owner\Downloads\data.csv’)

© Copyright 2013-2019 Analytics Vidhya