Productivity Tips for Jupyter Users | by Shinichi Okada | Towards Data Science

Table of ContentsIntroduction1. Startup files2. Auto reload3. Multi-cursor4. Exit confirmation5. Update you python packages6. Copying cells from another file
To be an efficient Jupyter user, there are few things you need to know. In this article, I am going through six tips that will improve your productivity. These tips work both in Jupyter Notebook and Jupyter Lab.
For more information on Jupyter hacks and version control, please read these articles.
If you are typing the same things again and again, startup files are your solution. Jupyter Notebook will access files within the start-up folder automatically. Generally, the default location is /Users/<your_profile>/.ipython/profile_default/startup in Mac.
You can find your startup directory by running this in a Jypyter Notebook cell.
get_ipython().profile_dir.startup_dir
Output can be like this.
'/Users/<your_profile>/.ipython/profile_default/startup'
You can create a file or files that you want to run in this directory when you start Jupyter Notebook.
For example, you create a file called 00-startup.py and add the following codes.
import pandas as pdimport numpy as npimport matplotlib.pyplot as pltget_ipython().magic('matplotlib inline')
When you are using magic %, you need to use get_ipython().magic() as seen above.
Restart your Jupyter Notebook. You can use Pandas or Numpy without importing them.
You can add more libraries depending on your needs. Example
towardsdatascience.com
When you modify an imported file, you have to restart the kernel. But autoreload reloads modules automatically before entering the execution of your cell.
You can add this to one of the cells and execute it.
%load_ext autoreload%autoreload 2
By saving the modified file, it enables auto-reload in another file.
If you want to always enable this setting, you can add it to ~/.ipython/profile_default/ipython_config.py.
If you don’t have the file, you can call ipython profile create first.
ipython profile create[ProfileCreate] Generating default config file: '/Users/yourname/.ipython/profile_default/ipython_config.py'[ProfileCreate] Generating default config file: '/Users/yourname/.ipython/profile_default/ipython_kernel_config.py'
Around line 31:
# ~/.ipython/profile_default/ipython_config.pyc.InteractiveShellApp.exec_lines = ['%autoreload 2']c.InteractiveShellApp.extensions = ['autoreload']
Auto-reload in action.
You can select multiple positions with your cursor. Click where you want to start, press Option, drag the cursor, start typing. You can use the Cmd+right arrow to jump to the far right of every line.
How many times have you typed y and pressed return after the Ctrl+C to shutdown? You can skip it by pressing the Ctrl+C twice.
Are you updating python packages regularly?
Check which packages you need to update. This will list outdated packages.
pip list -o# orpip list --outdated
You can run install -U to update a package.
pip install -U package
If you want to update all packages at once, run this in your terminal.
pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U
pip check verifies which installed packages have compatible dependencies. If you find a problem, you need to install the proper version using, pip install 'packagename==0.14.1'.
Other useful commands are:
pip reference
In Jupyter Notebook, you can copy-paste from another file by pressing cmd+v twice. If you press only once you get the warning below. In JupyterLab, you need to use c to copy a cell or cells and v to paste it into another file.
I hope these tips will help your productivity. What is your favorite tip?
Get full access to every story on Medium by becoming a member.