In[1]:
path=\'/Users/apple/Downloads/train.csv\'
open(path).readline()
Out[1]:
FileNotFoundError Tr
simple way is to move your files to be read under the same folder of your python file, then you just need to use the name of the file, without calling another path.
On osX
, Your path should be:
path = "/Users/name/Downloads/filename"
with name
the current user logged in
I do not know if it's what you were looking for, but it sounds to me something like this.
This is for linux (ubuntu) but maybe it also works on mac:
If the file is a pdf called 'book.pdf' and is located in your downloads, then
import subprocess
path='/home/user/Downloads/book.pdf'
subprocess.call(['evince', path])
where evince is the program that open pdfs in ubuntu
Many tutorials said that we should change Jupyter's workflow, but I didn't get it.
Finally, I find an easy way: Just drags file to this part.
I would suggest you to test it firstly:
copy this train.csv
to the same directory as this jupyter script in and then change the path to train.csv
to test whether this can be loaded successfully.
If yes, that means the previous path input is a problem
If not, that means the file it self denied your access to it, or its real filename can be something else like: train.csv.<hidden extension>
Here's a possibile solution (in Python):
Let's say you have a notebook with a file name, call it Notebook.ipynb. You are currently working in that notebook, and want to access other folders and files around it. Here's it's path:
import os
notebook_path = os.path.abspath("Notebook.ipynb")
In other words, just use the os module, and get the absolute path of your notebook (it's a file, too!). From there, use the os module and your path to navigate.
For example, if your train.csv is in a folder called 'Datasets', and the notebook is sitting right next to that folder, you could get the data like this:
train_csv = os.path.join(os.path.dirname(notebook_path), "Datasets/train.csv")
with open(train_csv) as file:
#....etc
The takeaway is that the notebook has a file name, and as long as your language supports pathname manipulations (e.g. the os module in Python) you can likely use the notebook filename.
Lastly, the reason your code fails is probably because you're either trying to access local files (like your Mac's 'Downloads' folder) when you're working in an online Notebook (like Kaggle, which hosts your environment for you, online and away from your Mac), or you moved or deleted something in that path. This is what the os module in Python is meant to do; it will find the file's path whether it's on your Mac or in a Kaggle server.