The Jupyter Notebook is a web-based application that records your data processing workflow from describing the steps, executing your code and visualising the results. It is similar to a writing a recipe or lab notebook. This notebook will introduce you to what Jupyter Notebooks can do and how you can use them effectively.
You will learn about:
Here are a few reasons why this training course uses Jupyter Notebooks:
This section will introduce you to Jupyter Notebooks through a series of tutorials from the official Jupyter Notebook documentation. The following topics are what you will need to understand for the training:
During the training, you will be working with Jupyter Notebooks in the JupyterLab environment. If you have not already done so, do check out the following JupyterLab tutorials:
+
button in the JupyterLab menu bar, or you can use the keyboard shortcut A
to insert a cell above the current one, or B
to insert a cell below the current one.Shift + Enter
.Enter
.You can get an overview of the keyboard shortcuts by hitting H
or go to Help/Keyboard shortcuts
Esc
- switch to command modeB
- insert belowA
- insert aboveM
- Change current cell to MarkdownY
- Change current cell to codeDD
- Delete cellEnter
- go back to edit modeEsc + F
- Find and replace on your codeShift + Enter
- Run a cellShift + Down / Upwards
- Select multiple cellsShift + M
- Merge multiple cellsMagic commands can make coding a lot easier, as you only have one command instead of an entire function or multiple lines of code.
Go to an extensive overview of magic commands
Overview of available magic commands
%lsmagic
Available line magics: %alias %alias_magic %autoawait %autocall %automagic %autosave %bookmark %cat %cd %clear %colors %conda %config %connect_info %cp %debug %dhist %dirs %doctest_mode %ed %edit %env %gui %hist %history %killbgscripts %ldir %less %lf %lk %ll %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %lx %macro %magic %man %matplotlib %mkdir %more %mv %notebook %page %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %pip %popd %pprint %precision %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole %quickref %recall %rehashx %reload_ext %rep %rerun %reset %reset_selective %rm %rmdir %run %save %sc %set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode Available cell magics: %%! %%HTML %%SVG %%bash %%capture %%debug %%file %%html %%javascript %%js %%latex %%markdown %%perl %%prun %%pypy %%python %%python2 %%python3 %%ruby %%script %%sh %%svg %%sx %%system %%time %%timeit %%writefile Automagic is ON, % prefix IS NOT needed for line magics.
See and set environment variables
%env
Install and list libraries
!pip install numpy
!pip list | grep pandas
Write cell content to a Python file
%%writefile hello_world.py
print('Hello World')
Load a Python file
%pycat hello_world.py
Get the time of cell execution
%%time
tmpList = []
for i in range(100):
tmpList.append(i+i)
print(tmpList)
Show matplotlib plots inline
%matplotlib inline
There are a number of ways that you can share Jupyter Notebooks with others. This enables you to share your workflows easily and collaborate with others.
nbviewer
to share nicely rendered Jupyter Notebooks.Binder allows you to open notebooks hosted on a Git repo in an executable environment, making the code immediately reproducible by anyone, anywhere.
Binder builds a Docker image of the repo where the notebooks are hosted.
This project is licensed under GNU General Public License v3.0 only and is developed under a Copernicus contract.