2

I am trying to do sentiment analysis with some data called "Reviews.csv". Here is the code:

import pandas as pd
df = pd.read_csv('Reviews.csv')
df.head()

When I run it it says:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-9-c259e3984e96> in <module>()
      1 import pandas as pd
----> 2 df = pd.read_csv('Reviews.csv')
      3 df.head()

4 frames
/usr/local/lib/python3.6/dist-packages/pandas/io/parsers.py in __init__(self, src, **kwds)
   2008         kwds["usecols"] = self.usecols
   2009 
-> 2010         self._reader = parsers.TextReader(src, **kwds)
   2011         self.unnamed_cols = self._reader.unnamed_cols
   2012 

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] No such file or directory: 'Reviews.csv'

Please help...

maria xu
  • 49
  • 2
  • 3

1 Answers1

4

You should run your Python script from the directory containing this file or use a relative or absolute path. The syntax you used is only valid if you have a file with that name, with permission to access it, in the same folder as your working directory. This is where you ran the script, not necessarily where your script is. The error means it is an invalid path or your user lacks permission to open it.

An absolute path always contains the root element and the complete directory list required to locate the file. For example, /home/sally/statusReport.csv is an absolute path. On Windows this will start with a drive letter usually.

A relative path might look like ../adjacent-folder/my-file.csv

Remember if you are not on Windows, casing also matters.

Palu Macil
  • 1,708
  • 1
  • 24
  • 34
  • I had the same issue on jupyter notebook(the csv was in the same folder as the notebook); I had to use the absolute path.I was using google colab. – wanjiku Apr 14 '22 at 05:21