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 belowCtrl + Enter
run selected cellsAlt + Enter
run the current cell, insert belowCtrl + 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 modeH
- show all shortcutsUp
- select cell aboveDown
- select cell belowShift + Up
- extend selected cells aboveShift + Down
- extend selected cells belowA
- insert cell aboveB
- insert cell belowX
- cut selected cellsC
- copy selected cellsV
- paste cells belowD, D
- (press the key twice) delete selected cellsZ
- undo cell deletionS
- Save and CheckpointY
- change the cell type to CodeM
- change the cell type to MarkdownP
- open the command palette
Edit Mode Shortcuts
Esc
- take you into command modeTab
- code completion or indentShift + Tab
- tooltipCtrl + ]
- indentCtrl + [
- outdentCtrl + A
- select allCtrl + Z
- undoCtrl + Y
- redoCtrl + Home
- go to cell startCtrl + End
- go to cell endCtrl + Left
- go one word leftCtrl + Right
- go one word rightCtrl + Shift + P
- open the command paletteDown Arrow
- move cursor downUp 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
- nbviewer - 'A simple way to share Jupyter Notebooks'
- nbviewer on github - host your own nbviewer on your local network
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)
Links
- Our Python Homepage
- Official Jupyter Documentation
- Bringing the best out of Jupyter Notebooks for Data Science - a great introduction and tips article