Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change working directory in Jupyter Notebook?

I couldn't find a place for me to change the working directory in Jupyter Notebook, so I couldn't use the pd.read_csv method to read in a specific csv document.

Is there any way to make it? FYI, I'm using Python3.5.1 currently.

Thanks!

like image 518
Y. Gao Avatar asked Feb 27 '16 02:02

Y. Gao


People also ask

How do I change the working directory in Jupyter lab?

Select your directory you want to have as home for your jupyter, and copy it with Ctrl + C , for example: C:\Users\username\Python Projects. Make sure to remove #, as it is as comment. Make sure to double slash \\ on each name of your path. Ctrl + S to save the config.py file !!!


3 Answers

Running os.chdir(NEW_PATH) will change the working directory.

import os
os.getcwd()
Out[2]:
'/tmp'
In [3]:

os.chdir('/')
In [4]:


os.getcwd()
Out[4]:
'/'
In [ ]:
like image 57
Robᵩ Avatar answered Oct 23 '22 00:10

Robᵩ


You may use jupyter magic command as below

%cd "C:\abc\xyz\"
like image 40
ManojK Avatar answered Oct 23 '22 02:10

ManojK


First you need to create the config file, using cmd : jupyter notebook --generate-config Then, search for C:\Users\your_username\.jupyter folder (Search for that folder), and right click edit the jupyter_notebook_config.py.

Then, Ctrl+F: #c.NotebookApp.notebook_dir ='' . Note that the quotes are single quotes. Select your directory you want to have as home for your jupyter, and copy it with Ctrl+C, for example: C:\Users\username\Python Projects.

Then on that line, paste it like this : c.NotebookApp.notebook_dir = 'C:\\Users\\username\\Python Projects'

Make sure to remove #, as it is as comment.

Make sure to double slash \\ on each name of your path. Ctrl+S to save the config.py file !!!

Go back to your cmd and run jupyter notebook. It should be in your directory of choice. Test it by making a folder and watch your directory from your computer.

like image 26
George Petropoulos Avatar answered Oct 23 '22 01:10

George Petropoulos