FileNotFoundError in JupyterLab (https://jupyter.org/try-jupyter/lab/)

340 Views Asked by At

Has anybody faced a FileNotFoundError in JupyterLab (https://jupyter.org/try-jupyter/lab/) when trying to read a .csv file? The file was uploaded in the same directory. I have used a CopyPath option to be sure that the path is correct. Still not working. Any suggestions on how can I fix this?

here is a snapshot of a simple code and an error

2

There are 2 best solutions below

1
On

This is unlikely to be an error with Jupyter.

Make sure that the ReadFile.ipynb and theFile.csv are in the same directory. If they are not, use a relative import.

enter image description here

If this still doesn't work, try the following synthax. This is independent of the path you provide.

pd.read_csv(r'C:\Users\aiLab\Desktop\example.csv')

Here r is a special character and means raw string. So prefix it to your string literal.

https://www.journaldev.com/23598/python-raw-string:

Python raw string is created by prefixing a string literal with ‘r’ or ‘R’. Python raw string treats backslash () as a literal character. This is useful when we want to have a string that contains backslash and don’t want it to be treated as an escape character.

See: pandas.read_csv FileNotFoundError: File b'\xe2\x80\xaa<etc>' despite correct path

Also, make sure that you don't have unwittingly copied an invisible character.

0
On

I ran into the same problem. Make sure your working directory is the same as your notebook and .csv file. Check this by running pwd. You can run ls to get the list of files in the working directory. If this helps you find the problem, try shutting down the running kernel completely and attaching a new one. This will change the working directory.