Jupyter Notebook Basics#
In the following cells, we will briefly introduce the Jupyter Notebook environment. For a more complete explanation, see Jupyter Notebook Documentation. For quick reference, refer to the following cheatsheets:
Jupyter notebook
What is a Jupyter Notebook?#
Jupyter Notebook App (formerly IPython Notebook) is an application running inside the browser. Notebook documents (or “notebooks”, all lower case) are documents produced by the Jupyter Notebook App, which contain both computer code (e.g. python) and rich text elements (paragraph, equations, figures, links, etc). Notebook documents are both human-readable documents containing the analysis description and the results (figures, tables, etc..) as well as executable documents which can be run to perform data analysis. And thats what make them powerful and cool.
The Jupyter Notebook App#
The Jupyter Notebook App is a server-client application that allows editing and running notebook documents via a web browser. The Jupyter Notebook App can be executed on a local desktop requiring no internet access (as we are doing here) or can be installed on a remote server and accessed through the internet.
In addition to displaying/editing/running notebook documents, the Jupyter Notebook App has a “Dashboard” (Notebook Dashboard) with title home which acts as a “control panel” showing local files and allowing to open notebook documents or shutting down their kernels.
Kernel#
A notebook kernel is a “computational engine” that executes the code contained in a Notebook document. The ipython kernel, referenced in this guide, executes python code. Kernels for many other languages exist (official kernels). Also, while here we are running Python 3 Kernel, you can also run Python 2 Kernel.
When you open a Notebook document, the associated kernel is automatically launched. When the notebook is executed (either cell-by-cell or with menu Cell -> Run All), the kernel performs the computation and produces the results.
Notebook Dashboard#
The Notebook Dashboard is the component which is shown first when you launch Jupyter Notebook App. The Notebook Dashboard is mainly used to open notebook documents, and to manage the running kernels (visualize and shutdown). The Notebook Dashboard has other features similar to a file manager such as navigating folders.
Installation#
The easiest way to install the Jupyter Notebook App is installing a scientific python distribution which also includes other common data science and scientific python packages. This is what we did by installing Anaconda. If you are more experienced, you can install each component separately (i.e install Python and then install Jupyter Notebook)
Running the Jupyter Notebook#
When you install the Jupyter Notebook App with Anaconda, you can launch it
by clicking on the Jupyter Notebook icon or by typing jupyter notebook
in a terminal (cmd on Windows) which will launch a new browser window (or a new tab) showing the Notebook Dashboard, a sort of control panel that allows (among other things) to select which notebook to open. We will look at a fe key concepts about running a Jupyter Notebook.
Notebook startup folder: When started, the Jupyter Notebook App can access only files within its start-up folder (including any sub-folder). No configuration is necessary if you place your notebooks in your home folder or subfolders
Shutting down the Jupyter Notebook App:Depending on your platform, you can use Quit on the Dashboard and this will kill the notebook server
Closing a Notebook (Kernel Shutdown): In the dashboard, you can shutdown, rename or delete notebooks
Cells#
Cells form the body of a notebook. There are two main cell types that we will cover:
A code cell contains code to be executed in the kernel and displays its output below.
A Markdown cell contains text formatted using Markdown and displays its output in-place when it is run.
You can always tell the difference between code and Markdown cells because code cells have that label on the left and Markdown cells do not
EXERCISE: Familiarise yourself with Jupyter Notebook#
Running an existing notebook, creating a new notebook
Saving, Naming/Renaming/copying, Creating/Adding/inserting/moving Cells etc
Creating Markdown Cells
Deleting cells
Running multiple cells
print('Dunstan')