Introduction To Anaconda and Jupyter Notebooks
Introduction To Anaconda and Jupyter Notebooks
Overview........................................................................................................................................................3
Jupyter Notebook...........................................................................................................................................3
Installing Anaconda.......................................................................................................................................3
LAUNCHING ANACONDA........................................................................................................................8
Creating a Notebook....................................................................................................................................10
Naming.........................................................................................................................................................10
Running Cells...............................................................................................................................................11
The Menus....................................................................................................................................................11
File Menu.................................................................................................................................................12
Edit Menu.................................................................................................................................................12
Headers.....................................................................................................................................................15
Creating Lists...........................................................................................................................................16
Overview
The Jupyter Notebook is an open-source web application that you can use to create and share documents that
contain live code, equations, visualizations, and text.
Jupyter Notebook is maintained by the people at Project Jupyter. Jupyter Notebooks are a spin-off project
from the IPython project, which used to have an IPython Notebook project itself. The name, Jupyter, comes
from the core supported programming languages that it supports: Julia, Python, and R. Jupyter ships with
the IPython kernel, which allows you to write your programs in Python, but there are currently over 100
other kernels that you can also use.
Jupyter Notebook
The Jupyter Notebook is not included with Python, so if you want to use it, you must install Jupyter directly
or using Anaconda. Anaconda is a distribution of packages built for data science including everything that
we need for this module under one roof. Without Anaconda you would have to install and manage each
separately.
Installing Anaconda
Just so you are aware, it is possible to just install Jupyter Notebook on its own (but please don’t) when using
Python 3 (as we are), you can use a tool bundled with Python called pip to install Jupyter Notebook like
this:
However, we will use the most popular distribution of Python called Anaconda. Anaconda has its own
installer tool called Conda that you could use for installing a third-party package. However, Anaconda
comes with many scientific libraries preinstalled, including the Jupyter Notebook, MathPlotLib, Pandas,
NumPy, Scikit, etc., so you don’t actually need to do anything other than install Anaconda itself.
Install where prompted into the C: drive programs folder (different on pcs, laptops, etc.)
Make sure both of the following boxes are NOT TICKED and click Install:
After installation, you should see Completed! Click Next.
You may be prompted to update the Anaconda Navigator from time to time such as follows. Always click to
update. It may require you to exit the Navigator and reopen it again but it usually provides a launch button at
the end of the update:
Launching Jupyter Notebook
We wish to open up Jupyter Notebook.
As an alternative to going through the Anaconda Navigator, you can just click on Jupyter Notebook quick
launch button in the dropdown list under Anaconda in the start menu. You can also launch it from the
Anaconda Prompt by typing Jupyter notebook and pressing enter but this is rarely used:
Starting the Jupyter Notebook Server
Now that you have Jupyter Notebook opened, let’s learn how to use it. Irrespective of how you launch it,
Jupyter will start up in your default browser on the following URL: http://localhost:8888/tree. Localhost is
not a website, but it indicates that the content is being served from your local machine: your own computer
is the local host. Your browser should now look something like this:
Note that right now you are not actually running a Notebook, but instead you are just running the Notebook
Server. You will actually see what is currently running on the terminal when you start to create Notebooks.
For example:
Creating a Jupyter Notebook
The Jupyter Notebook is quite useful for sharing data. You can turn your Notebook into a slideshow or share
it online with GitHub. If you want to share a Notebook without requiring your users to install anything, you
can use binder for that. Google and Microsoft both have their own version of the Notebook that you can use
to create and share your Notebooks at Google Colaboratory and Microsoft Azure Notebooks respectively.
You can browse really interesting Notebooks there as well. Ctrl + click the links to view.
Project Jupyter recently launched their latest product, JupyterLab. JupyterLab incorporates Jupyter
Notebook into an Integrated Development type Editor that you run in your browser. You can kind of think
of JupyterLab as an advanced version of Jupyter Notebook. JupyterLab allows you to run terminals, text
editors and code consoles in your browser in addition to Notebooks.
Running Cells
A Notebook’s cell defaults to using code whenever you first create one, and that cell uses the kernel that you
chose when you started your Notebook. In this case, you started you chose Python 3 as your kernel, so that
means you can write Python code in your code cells. Since your initial Notebook has only one empty cell in
it, the Notebook can’t really do anything.
Thus, to verify that everything is working as it should, you can add some Python code to the cell and try
running its contents. Let’s try adding the following code to that cell:
Running a cell means that you will execute the cell’s contents. To execute a cell, you can just select the cell
and click the Run button that is in the middle of the row of buttons along the top or just press Shift + Enter
on the keyboard. The output should look like this:
If you have multiple cells in your Notebook, and you run the cells in order, you can share your variables and
imports across cells. This makes it easy to separate out your code into logical chunks without needing to
reimport libraries or recreate variables or functions in every cell.
When you run a cell, you will notice that there are some square braces next to the word In, on the left of the
cell. The square braces will auto fill with a number that indicates the order that you ran the cells. For
example, if you open a fresh Notebook and run the first cell at the top of the Notebook, the square braces
will fill with the number 1.
The Menus
The Jupyter Notebook has several menus that you can use to interact with your Notebook. The menu runs
along the top of the Notebook just like menus do in other applications. Here is a list of the menus:
File Cell
Edit Kernel
View Widgets
Insert Help
Let’s discuss the menus one by one. We can’t go into detail for every single option in every menu, so we
will focus on the items that are unique to the Notebook application.
File Menu
In the File Menu, you can create a new Notebook or open a pre-existing one. This is also where you would
go to rename a Notebook. The Save and Checkpoint option allows you to create checkpoints that you can
roll back to if you need to. Rolling back enables you to return your code to a previous state, perhaps one
where it was stable, before you did something you later decided was erroneous. Checkpoints and rollback
are common in programming.
Edit Menu
In the Edit Menu you can cut, copy, and paste cells. This is also where you can delete, split, or merge a cell.
You can reorder cells here too. Note that some of the items in this menu are greyed-out. The reason for this
is that they do not apply to the currently selected cell. For example, a code cell cannot have an image
inserted into it, but a Markdown cell can. If you see a greyed-out menu item, try changing the cell’s type and
see if the item becomes available to use.
The Heading cell type is no longer supported and will display a dialog that says as much. Instead, you are
supposed to use Markdown for your Headings.
The Raw NBConvert cell type is only intended for special use cases when using the nbconvert command
line tool. Basically, it allows you to control the formatting in a very specific way when converting from a
Notebook to another format. We will discuss again later.
The primary cell types that you will use are the Code and Markdown cell types. You have already learned
how code cells work, so let’s learn how to style your text with Markdown.