Absolute and relative paths

Screen Link:
https://app.dataquest.io/m/349/project%3A-learn-and-install-jupyter-notebook/10/absolute-and-relative-paths

I am not able to understand what the text and the live images, below that in the given link are trying to say. Please if someone can help me understand what the images are saying? Should i use absolute paths or relative paths? How to create a new folder in the directory?

2 Likes

Hi @uditchauhan:

According to the instructions of the mission step, you are supposed to:

Copying AppleStore.csv to /home/alex is simply a matter of copy-paste. Once the data set is pasted at /home/alex , we can directly use open('AppleStore.csv') .

Basically this step is meant to illustrate to you the importance of file directories. A general rule of thumb is to place the dataset and the jupyter notebook in the same base directory, in the mission’s case /home/alex. This is because the notebook references the file in the base directory. If the file is not found (i.e. no file name matches the file specified in the open() argument), the python interpreter used in jupyter throws a FileNotFoundError.

In this case there are 2 solutions–one is to make copy the notebook in the base directory (/home/alex) and run it from there and the other is to use the path to reference the location of the notebook. This can be useful if you wish to have a centralized location to store all your datasets, but I usually stick to the conventional method of putting both the notebook and the dataset in the same base directory.

Since it is not specified which method is required, feel free to use any of the two.

  1. Copy the notebook to /home/alex
open('AppleStore.csv')


You can do this by returning to the menu screen by clicking the jupyter icon to do the copy-pasting.


  1. Notebook remains in /home/alex/dataset
open('/home/alex/dataset/AppleStore.csv')

# or

open('dataset/AppleStore.csv') # can also be expressed as open('./dataset/AppleStore.csv')

In the second case, the second method is the relative path since the notebook is are already at /home/alex but the dataset is at /home/alex/dataset, which is a directory below that of the notebook. The alternative expression containing ./ means open the file from the current working directory of the notebook (i.e. /home/alex), which is a more explicit way of specifying the relative path, but this is already done by default, thus you do not really have to specify it. (i.e. I used it for explanation’s sake)

In this case since you don’t need to create a new folder but instead navigate through the filesystem.

Edit: It seems like they have already done the copy-pasting for you so you just have to specify the name of the .csv file.

Hope this clarifies!

3 Likes

this is when i use the jupyter notebook within dataquest. How to see the file which is work on in my pc if i am using the inbuilt jupyter? i cant see anything. Its very confusing now. I installed jupyter manually through pip. There is so much chaos, I dont understand where do i work from and where my files are getting saved and how to create it if i am using jupyter locally , I got the image you sent but that is not happening in my local jupyter.

Hi @uditchauhan:

You will have to launch jupyter prompt from anaconda navigator or through the command line to view the file. You may refer to this guide. I would recommend installing jupyter on Anaconda for less confusion. Please download the dataset and the notebook to simulate it on a local environment.

i went through the guide but it doesnt solve my doubt. I installed through pip and i had no problem in that. The things you have explained apply to the inbuilt notebook. I want to know how to do it locally on my jupyter, my doubt is as simple as that, how to create the directory with my jupyter and where to see it in my pc.

1 Like

When you type jupyter notebook in your terminal does it launch this page?

yes sir the same page launches

Then create a new file by clicking new as shown in the instructions. On the top right of the menu

done @masterryan.prof

So it works now? @uditchauhan. You just have to download the two files (dataset and the notebook file) and place them in your desired base directory. Then navigate to that particular directory based on your file hierachy.

i meant i did the step of opening new and then python 3. After that? I thought you were telling steps. Download from inbuilt jupyter? i have to place them through this pc in my laptop right? Sorry if this is dumb but this is my main confusion as to where i can see and naviagate and copy paste the file and how. As in the chapter absolute and relative paths i cant understand. I searched and installed through pip on my own but in this chapter i am totally stuck cant move ahead

For example I place the desired file in my Desktop. So All I need to do is to click on the Desktop folder and the files will be there. Clicking on them again will open them up. You can move your files manually through the GUI by dragging and dropping files using file explorer/ finder and then opening them. An alternative way would be to use the command line. I think it is better if you first understand and know how to navigate the jupyter GUI before moving on to understand the CLI.

pff sir. I want to create my datasets folder with all those folders have to do that from this pc? is yes then in c drive?. And then i have to move my file from suppose downloads to my dataset folder right?

I recommend creating it in desktop but its totally up to you. I think you should watch some tutorials to get familiar of the jupyter interface.

searching tutorials since two days but not getting anything related to my doubt, if you understood what my doubt is then please recommend something to me or guide me something i am not able to process this. I cant go ahead sir

The video on the guide should be sufficient. This is also good:

that guide doesnt solve my doubt. As for the video you shared i am watching it right now immediately. I dont know my doubt was fairly simple but you didnt gave replies to my specific questions which i asked. I will try to read our conversations once again. If you dont want that, just explain me one thing where are my files being saved andhow can i create the directory even if my use inbuilt jupyter. My doubt will remain the same

Your files will be saved based on your current working directory in jupyter or where u click “new” on the jupyter menu interface.The view I showed in the screenshot earlier was a top down view of my C:\ drive. An example of how the base directory should be like is shown below.

The dataset cats_and_dogs_small and the jupyter notebook Demo_4-MNIST-using-convnets.ipynb are in the same working directory.

You were asking more and more questions. I think it is better if you were to put them in a different topic so that they can be addressed separately.

Yes you will have to do that as I described earlier.

1 Like