Jupyter Workflow and Tips

By: Michael Silverstein

All keyboard shortcuts listed below are for Mac. Substitute Cmd for Ctrl for the Windows equivalent

Just a normal day doing some data analsis

My prefered Python scripting environment for data analysis is Jupyter Lab, which is included with Anaconda. To initialize a Jupyter Lab session, simply open your terminal and enter the command jupyter lab.

init lab

Jupyter Lab Features

That should launch a new tab in your web browser. This tab is where all of my coding will take place for the day(!). The advantages of Jupyter Lab is that:

Creating Notebooks and Terminal sessions

Creating a new notebook is easy, just click the + icon in the upper left to open a Launcher tab and then select Python 3 under Notebooks. You can then easily name the new notebook by right clicking the new tab and selecting Rename Notebook....

From the Launcher you can also create a Terminal session under Other. I find this extremely useful because it centralizes all of my work. Now you can work on notebooks and do any terminal operations from the same browser tab (terminal commands can over course be used directly in Jupyter cells with !<normal terminal command>, however many operations are usually more easily executed with a terminal session).

launcher

Now you are all set to get coding!

Jupyter tips

Notebook format

Notebook format, in my opinion, is one the most overlooked facets of scientific computing. An organized LINEAR notebook is the main difference between reproducible and irreproducible code. Each cell should be sequentially runnable. If you're finding that you have to run cells out of order, it may be best to split the work in that notebook into two.

I always start my notebooks with the following cells:

  1. A title cell [Markdown]
  2. An import statements cell (import all packages here) [Code]
  3. Define all multi-use custom functions (defining these at the top ensures generalized application in following cells).
  4. First task description [Markdown]
  5. First task [Code]
  6. etc...

Some formatting tips:

Here is a sample notebook


Jupyter Tutorial

Here's how I start my notebooks

Functions

First task

Thinking about random things


Jupyter keyboard shortcuts

THESE WILL CHANGE YOUR LIFE! At least they did for me.