Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help - FileNotFound
#1
Hi all,

I am a new learner of python so forgive if my question is too rookie. I am using Colab to start learning. I have a csv file on my desktop folder. When I need to read the file, the problem is that the directory is incorrect. I googled many solutions but they did not work for my case at all.

Here is the directory of my file: C:\Users\USER\Desktop\Learning\GrandmaCan
File name is: Salary_Data.csv
   

The error on Colab is as follows:

---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-14-2ff469c75df4> in <cell line: 3>()
1 import pandas as pd
2
----> 3 data = pd.read_csv(r'C:\Users\USER\Desktop\Learning\GrandmaCan\Salary_Data.csv')
4
5 print(data)
---------------------------------------------------------------------------

I tried to modify my code but there is another error:

---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-15-f144dd2c210b> in <cell line: 3>()
1 import pandas as pd
2
----> 3 data = pd.read_csv('C:\\Users\\USER\\Desktop\\Learning\\GrandmaCan\\Salary_Data.csv')
4
5 print(data)
---------------------------------------------------------------------------
   

How can i solve the directory problem?
Thanks in advance
Reply
#2
Hi @SmallGuy,

I don't use either Colab neither than pandas or Windows...

But if I were you I will try some basic test without pandas like this:

from os.path import isfile #info https://docs.python.org/3/library/os.path.html#os.path.isfile

print( isfile('C:/Users/USER/Desktop/Learning/GrandmaCan/Salary_Data.csv') )
it should output True if not something is wrong with the given path or how you running Python or even permissions acess on the files. ?

note: that the backslash \ changed into slash /
[Image: NfRQr9R.jpg]
Reply
#3
Thanks SpongeB0B.

I tried the code on both Colab and Jupyter. not worked.

I run the csv file successfully on pyCharm so perhaps it is some access problem (?) to the files on my local drive. I tried to access my other files on the web-based environments, and all didn't work. I just cant find any solutions from internet so far.
Reply
#4
I guess that your Windows OS device name is not USER.
In tutorial they can put USER in path,this mean that you should replace width your device name
Let say eg you have eg kent as name,usually see name when logon to Windows.
Then path would be like this.
'C:/Users/kent/Desktop/Learning/GrandmaCan/Salary_Data.csv'
Tips make your own simpler folder path eg C:\div_code then put Salary_Data.csv and .py files in his folder,
simpler in long run than have a long Desktop path that use device name in it.
Reply
#5
Google Colab notebook is hosted on Google’s cloud servers, there’s no direct access to files on your local drive.

In order to use local files in Colab it must be uploaded. On leftmost column last icon is Folder (below search and {x}), clicking on that opens additional pane, on that click on upload icon (upper row) and file upload dialog window will open. After uploading is finished file can be used normally.

Alternatively from Python one can use files modul from google.colab library if file is on local drive or drive library if its located on Google Drive
snippsat likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#6
(Aug-12-2023, 09:27 AM)perfringo Wrote: Google Colab notebook is hosted on Google’s cloud servers, there’s no direct access to files on your local drive.

In order to use local files in Colab it must be uploaded. On leftmost column last icon is Folder (below search and {x}), clicking on that opens additional pane, on that click on upload icon (upper row) and file upload dialog window will open. After uploading is finished file can be used normally.

Alternatively from Python one can use files modul from google.colab library if file is on local drive or drive library if its located on Google Drive

Thanks mate.
Reply
#7
(Aug-12-2023, 08:10 AM)SmallGuy Wrote: I tried the code on both Colab and Jupyter. not worked.
Miss this part,perfringo clear it up,here also a Thread you can look at.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020