I can't get the python on jupyter read my file on desktop

I am using python on jupyter notebook. I have tried to open a data file with the following command to open a file on my desktop. But it doesn’t open it and gives error message. what’s wrong? here is my command line:
df=pd.read_csv(‘C:\Users\Fariba\Desktop\Advertising.csv’)

What is the error you are getting?

I see you are pasting in the windows path as a string, I would suggest prefixing it with an r , see here:

df=pd.read_csv(r'C:\Users\Fariba\Desktop\Advertising.csv')
1 Like

This seems to be posted under the wrong category I suspect? If it was in the right category, a JupyterHub wouldn’t be able to access your local files.

As afonit was getting at, there are Windows-specific challenges that aren’t present in Unix-based systems and so you have to pay special attention to the specifics concerning advice when looking into this type of thing. That being said, there is already a lot on this on the internet. See python - How do you load a csv file format to jupyter notebook? - Stack Overflow and python - whitespaces in the path of windows filepath - Stack Overflow and How should I write a Windows path in a Python string literal? - Stack Overflow. (Also here gives you a sense there are different errors you may see, see below, and at least a few ways to deal with this type of issue.)

Windows paths that are very long can also be an issue, but that doesn’t look like the problem here unless you are using a representative example and not the actual path.

You should be able to use ls and %cd and pwd in your running notebook to move around & list items in the directories to verify what you see as you change directories. Including information you see when troubleshooting that way would be expected if none of the approaches suggested are sorting this out.

Finally, OneDrive commonly can interfere as it changes where files are actually on your system. If you use that make sure to look into that.


Plus, please read Getting good answers to your questions . I particularly like the resource How do I ask a good question? referenced at the bottom there as it provides a thorough guide to making a good post. Those resources will cover what afonit was prompting when asking about what the error is. It is definitely frowned upon to not include the details of the error. Just saying you got an error isn’t sufficient.

Also, it is heard to judge if this post is pertinent to this forum.
In most cases I’d expect if you were using that code via Python or IPython in a console or running a script, both of which are the more traditional ways to use Python/IPython, you’d have the same issue you report here. And so it wouldn’t be a Jupyter issue. This is an exercise you should do when considering where to post. Once you understand things better, it can be a mental exercise. If you had one that and seen differences then you’d include these details in your post.

1 Like

Thank you, That worked. But how could we know that this is necessary?

formightez,
Thank you for the detail and sorry for my extreme lack of knowledge in the domain. As you see, I’m a beginner enough not to know the mentioned differences!