If you?ve ever been frustrated with Jupyter Notebook, I hear you. It?s a little bit of a different development environment then IntelliJ and starting out can seem clunky and slow. Which leads to frustration and possibly abandoning this text editor.
However, there are many many improvements you can make to Jupyter which will improve your experience
This article assumes you have Jupyter installed, and if you don?t, just run the code below in your terminal.
# Install jupyterpython -m pip install –upgrade pippython -m pip install jupyter# Install nbextensions for laterpip install jupyter_contrib_nbextensionsjupyter contrib nbextension install –user# Open the notebook in your current directoryjupyter notebook
Keep in mind, there is a version of jupyter notebook called jupyter lab which will not be covered here. Many of the extensions don?t work perfectly yet in lab so we?re going to stick to the notebook version.
Once you?ve run jupyter notebook you should be met with a directory page of all the files in the path you opened jupyter in. Now, create a new notebook in the top right corner.
Create a new Notebook
Jupyter has two modes edit mode and command mode.
In edit mode, you can type code, text, etc. into a cell, and the colour around the cell will be green. While you?re in edit mode, you can move to command mode by pressing esc.
In command mode, you can move from cell to cell, and the colour around the currently selected cell will be blue. While you?re in command mode, you can move to edit mode on the cell you?ve selected by pressing enter.
Edit Mode in Green (Left); Command Mode in Blue(Right)
If you take away anything away from this article, just remember cmd + shift + p. This will pull up the quick select bar, which will have all the hotkeys, shortcuts, and commands, all in an easy to use bar. And if you forget something, you can always pull up the quick select bar to remind yourself.
Testing the Quick Select Bar
Here are some hotkeys you should know for command mode:
# Insert cell above currently selected cell# A# Insert cell below currently selected cell# B# Delete cell currently selected cell# dd# Change cell type of currently selected cell# M (Markdown)# Y (Code)# Switch currently selected cell to edit mode# Enter# Select multiple cells# Shift + up/down
Here are some hotkeys you should know for edit mode:
# Execute cell (run code)# shift + enter# Split cell into two cells# CTRL + SHIFT + – (at the location you want the split)# Smart Suggestion# (After the last char of a method or object) + tab# Documentation for a method or object (how much do you want?)# Shift + tab# Shift + tab + tab# Shift + tab + tab + tab + tab
Here are some hotkeys while in edit mode for editing your code:
# See documentation for a method# PackageName.MethodName()?# Open documentation window for a method# PackageName.MethodName()??# Use multiple cursors# Hold down ‘alt’# Quick comment line(s)# Shift + /# Indent / dedent line# Cmd + [# Cmd + ]
Now let?s bring up the nbextensions we installed earlier. To access these, you need to navigate back to the original window which opened up when you launched jupyter notebook and select the Nbextensions tab. These are jupyter packages that will dramatically improve your workflow, and I?m going to go over the ones I think will help you the most. To activate any of the extensions search for them, and click the checkmark.
Navigating to Nbextensions
Notify
This will display a desktop notification when the kernel becomes idle. Use this when you?re running tasks that take more than a couple of seconds to complete. Great for large models.
Code Folding
While in edit mode, a triangle appears in the gutter to fold your code. Good when you have large functions you want to hide for readability.
tqdm_notebook
Creates a progress bar for your code. If you?re the type of person who needs to know how fast things are being run, this can work for you. Just beware setting it up for every function can be tedious. It needs to be installed here.
Zen mode
Makes things a bit less cluttered. Make sure to turn off the backgrounds in the settings.
Zen Mode
A Code Prettifier
Cleans up, formats, and indents your code, so you don?t have to. The hotkey is ctrl + l for your cell for ctrl + shift + l for the whole notebook.
Autopep-8
Make sure you have run pip install autopep8 –user on your local machine. This will make sure you?re following the correct python coding conventions. The hotkey is alt + a for your cell for alt + shift + a for the whole notebook.
Scratchpad
This is honestly the best extension I?ve ever installed for jupyter notebook. It allows you to create a temporary cell to do some quick calculations in without creating a new cell in the workbook. Toggle with ctrl + b. It has saved me countless hours in calculation time.
Install the Scratchpad extension ? you?ll never go back
Toggle All Line Numbers
This should be included, but it is not. So make sure you toggle it on in the extensions.
All these commands should keep you organized and focused when working in your notebook. Part 2 of this post, will be around jupyter notebook magic functions. These are specific to the python kernel generated by jupyter, and provide even more functionality for the notebook.
As always, I hope you learned something new. And, the github link can be found here.
Cheers.
Additional Reading
http://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions.html
28 Jupyter Notebook tips, tricks and shortcuts
We have expanded the post and will continue to do so over time – if you have a suggestion please let us know. Thanks to?
www.dataquest.io
Advanced Jupyter Notebook Tricks – Part I
I love Jupyter notebooks! They’re great for experimenting with new ideas or data sets, and although my notebook?
blog.dominodatalab.com
Five Tips To Get You Started With Jupyter Notebook
We’ve discussed a few reasons to use Jupyter Notebooks as a GIS user. From visualization of your data to the recent?
www.esri.com
https://github.com/jbwhit/jupyter-tips-and-tricks