RasPi Banner

Jupyter

Jupyter (Jupyter Notebook) is a web application, in which you can create and share documents which contain live code, visualizations, documentation and more. It is a great tool for data science, and for sharing Python concepts. R and Julia are supported as well.

Jupyter does have a successor: JupyterLab. However, even in JupyterLab, Jupyter notebooks are a standard component, so it's worthwhile to get acquainted.

Installation

The Official Jupyter Documentation has you perfectly covered. But to get started, you only need to do the following:

  • Setup your Python virtual environment and start it up
  • Install Jupyter via pip:
pip3 install jupyter
  • Navigate to a folder where you wish to keep your notebooks
  • Start Jupyter and enjoy
jupyter notebook

Keyboard Shortcuts

It's good to know the keyboard shortcuts in your Jupyter environment. You'll be using those a lot. We have broken down the essential Jupyter shortcuts into sections - they align with 2 modes in Jupyter - 'command' and 'edit' mode.

Therre are more shortcuts available, and you can create your own. Mastering these basics is however good enough to really rock Jupyter

Universal shortcuts

These shortcuts work bot in command and edit mode.

  • Shift + Enter - run the current cell, select below
  • Ctrl + Enter run selected cells
  • Alt + Enter run the current cell, insert below
  • Ctrl + S save and checkpoint

Command Mode Shortcuts

To go to command mode, press ESC. You can use the following important keyboard shortcuts:

  • Enter - take you into edit mode
  • H - show all shortcuts
  • Up - select cell above
  • Down - select cell below
  • Shift + Up - extend selected cells above
  • Shift + Down - extend selected cells below
  • A - insert cell above
  • B - insert cell below
  • X - cut selected cells
  • C - copy selected cells
  • V - paste cells below
  • D, D - (press the key twice) delete selected cells
  • Z - undo cell deletion
  • S - Save and Checkpoint
  • Y - change the cell type to Code
  • M - change the cell type to Markdown
  • P - open the command palette

Edit Mode Shortcuts

  • Esc - take you into command mode
  • Tab - code completion or indent
  • Shift + Tab - tooltip
  • Ctrl + ] - indent
  • Ctrl + [ - outdent
  • Ctrl + A - select all
  • Ctrl + Z - undo
  • Ctrl + Y - redo
  • Ctrl + Home - go to cell start
  • Ctrl + End - go to cell end
  • Ctrl + Left - go one word left
  • Ctrl + Right - go one word right
  • Ctrl + Shift + P - open the command palette
  • Down Arrow - move cursor down
  • Up Arrow - move cursor up

Tips

nbviewer

Your Jupyter Docs are very portable and you can share them with friends and colleagues, or just keep a repository of code snippets. You can, however, take the whole thing to the next level.

Checkout a great tool to share your notebooks with the world, or simply host your notebooks on a Pi on your own network: enter nbviewer

Shell Commands in Jupyter

Switching between Python interpreter, Your scripts and the Shell gets boring. Jupyter takes away some pain. You can run Shell commands from within Jupyter by prefixing them with !. Neat. Next time I would want to find the right path / filename, I would simply type:

!pwd
!ls

And it gets better. You can pass values from/to the shell and your notebook. For example:

directory = !pwd
print(directory)