You have 2 free member-only stories left this month.
Data Science
Productivity Tips for Jupyter Users
Make your workflow with Jupyter Notebook and JupyterLab more efficient
Table of ContentsIntroduction1. Startup files
2. Auto reload
3. Multi-cursor
4. Exit confirmation
5. Update you python packages
6. Copying cells from another file
Introduction
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.
Startup files
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 pd
import numpy as np
import matplotlib.pyplot as plt
get_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
Auto reload
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.py
c.InteractiveShellApp.exec_lines = ['%autoreload 2']
c.InteractiveShellApp.extensions = ['autoreload']
Auto-reload in action.