Getting started with Jupyter Notebook

Tony Staunton
Python Code Academy
9 min readFeb 16, 2022
Jupyter Notebook

The Jupyter Notebook is one of the most popular integrated development environments (IDE) for data science projects, and for good reason. It allows you to run code, and receive output in the same document. When working on a data science project, you’ll be writing a lot of code, and running it immediately to view the results. As a data scientist you will often want to present your work, and results to others, which the Jupyter Notebook is perfect for, as you can add text explanations, write formulas, and display visualizations. All of these features make it the perfect IDE for data scientists. As if all of that wasn’t enough to love about Jupyter, another great advantage is that it’s completely free to use. You can download it here, and get started right away.

In this article, we’ll discuss how to install Jupyter Notebook on your computer and how to use it to create data science projects. Let’s get started.

If you need to install Python check out my free guide here.

How to download the Jupyter Notebook

There are two common ways to install Jupyter on your computer:

Installing with pip

Pip is a popular package manager for python libraries and it can be used to install Jupyter Notebook. You may need to create an empty folder where you plan to download the notebook. Before proceeding I would recommend that you update your version of Pip to the most recent to avoid any potential dependency issues. To do this, open up your terminal or command line, and type in the following:

pip install –upgrade pip

Now, you can navigate to the newly created directory and enter the following command:

pip install jupyter

This will install Jupyter on your computer.

Unsure about how to use the command line? Check out my introduction article here.

Installing Jupyter with Anaconda

Anaconda is a Python distribution tool that contains a large number of packages for data science, including the Jupyter Notebook. This means that when you download and install Anaconda you also get Jupyter Notebook.

To download Anaconda, go to https://www.anaconda.com/products/individual, select the appropriate version for your computer, and download the installation file.

Once the download is complete, open the installation file to start the install on your computer. One word of caution before you go and click Next on everything, when you reach the option shown below, make sure that you select “Add Anaconda3 to my PATH environment variable”. When you select it, the option will turn red but don’t worry, select it and click Install.

The Anaconda installation can take some time, so hang in there in case you’re tempted to restart!

Launching the Jupyter Notebook

Jupyter Notebook is a web-based tool, so it requires your web browser to work. To open Jupyter Notebook, you can search for the application on your computer and select it. Alternatively, you can open it up from your terminal or command line with the following command:

jupyter notebook

This powers the local server for Jupyter Notebook (which is typically localhost:8888/tree), and opens Jupyter Notebook on your default browser.

Using Jupyter Notebook to write Python

When you open up the Jupyter Notebook, you should see an interface similar to the one shown below:

You’ll notice that there are three tabs on the dashboard:

  1. Files: This tab shows the files you have in a specific location. You can click on the folder names to access the files within that folder.
  2. Running: This displays the terminals and notebooks that are currently running
  3. Cluster: This is provided by IPython, and is primarily used for parallel computing amongst a distributed network of computers

In the top-right corner, you’ll see buttons to Quit and Logout. Quit is used to shut down the server (or kernel) while Logout is used to sign out of your Jupyter Notebook. Below these two buttons, you’ll find buttons for Upload and New, which is a dropdown menu option.

To create a new Jupyter Notebook file (with extension IPYNB), click on the New dropdown. Then click on the Python 3 option to open a new Jupyter Notebook:

When you see the screen above, you are almost ready to write Python within the notebook. But just before you do, let’s get familiar with the Jupyter Notebook interface.

Understanding the Jupyter Notebook Interface

Within a Jupyter Notebook file the area where you write Python code is called a cell. You can see a cell in the image above, which is waiting for input. Jupyter Notebook allows you to run a cell, view the result, and then continue to add new cells. When using Jupyter Notebook, most of your work will be done in these cells.

Now, let’s take a look at how to navigate the Jupyter Notebook interface.

The Notebook Name — The name of your notebook is next to the Jupyter Notebook logo in the top left corner of your screen:

By default, the notebook name is set to Untitled. You can change this name by clicking it. A dialog box will pop up where you can rename the notebook. Let’s rename the notebook to ‘My First Notebook’:

Next to the name of your notebook, you’ll notice a checkpoint. Jupyter Notebook automatically saves when you edit the notebook cells. The checkpoint simply shows the last time the notebook was saved.

The Menu Bar

The Menu Bar contains different menus that you’ll be using when working within the notebook.

Let’s briefly discuss each of them:

  • File: This is used for access file options. You can save, rename, print, download, close, etc.
  • Edit: This is used to edit existing cells. You can delete, move, merge, and split cells.
  • View: This is used to personalize the appearance of your notebook
  • Insert: This is used to insert new cells
  • Cell: This is used to run a cell after you have entered Python code. You can choose to run a specific cell, the cell below it, or the cell above it.
  • Kernel: Think of the kernel as the engine of the notebook. If the Kernel is dead, no notebook cell will run. When working with Kernels, it’s important to understand its state at any given time. Let’s take a look and see what each option in the Kernel menu means:
  • Interrupt: This is used to stop a cell that is currently running. Use this option in situations where a piece of code is taking too long to complete, or if you happen to have created an infinite loop. Interrupting the kernel stops all cells.
  • Restart: This is used to restart the Kernel. When you perform a restart the output of all cells will be maintained as will your code within the cells.
  • Restart & clear output: This restarts the Kernel and clears the output from the notebook. This means that your code and cells are clean and ready to run.
  • Restart & run all: This option will restart the Kernel and run all the cells in one go.
  • Reconnect: Sometimes a kernel will die for no particular reason. When this happens you can reconnect using this option.
  • Shut down: This is used to shut down the kernel and stop all processes
  • Change kernel: When you have more than one anaconda virtual environment installed, you can switch between different kernels
  • Widget: Widgets are used to build interactive GUIs on your Notebook
  • Help: This is used to find resources when working with Jupyter Notebook, or the key libraries that come with it

The Command Icons

This is another critical area when working within a Jupyter Notebook. These icons allow you to perform certain functions on cells or on a single cell. Let’s examine what each button does:

  1. The first icon is used to save your file
  2. The + icon adds a new cell below the current cell
  3. Cut a cell or selected cells
  4. Copy a cell or selected cells
  5. Paste a cell or selected cells
  6. Move a cell up
  7. Move a cell down
  8. Run a cell
  9. Stop a cell
  10. Restart the Kernel
  11. Restart the Kernel and run all
  12. Change the cell type into another format
  13. Open the command palette

Cells

As mentioned earlier, this is where you run Python code. After a cell has run or executed, that cell then becomes numbered. A cell without a number implies that it has not been run.

A cell with an asterisk indicates that it’s currently running. After your code has run, the cell changes to the next number. If your code generates an infinite loop, the asterisk will remain there while the notebook is running. In this instance you may need to interrupt the Kernel.

Running Python Code

Now that we have discussed the interface of the notebook. It’s time to run some code.

After entering code in a cell, you run it by clicking the run button from the command palette above. Then, you can add a new cell by clicking on the + icon. This is a repetitive, and unproductive process, luckily there is a shortcut, use ‘Shift+Enter’ to run a cell and add a new cell below.

Doing more

The beauty of Jupyter Notebook is that its functionality goes beyond writing and running Python code. Think of your notebook as a word processing document that can be edited to suit your needs. To change how a cell interprets input, you can change the cell type. This is done from the dropdown bar in the command palette.

Let’s take a look at the other cell types.

Markdown

Markdown is used to write plain text. You can write in various heading types, including:

  • Heading 1
  • Heading 2
  • Heading 3, and more

You can add text that is bold, or in italics. To write a piece of text using heading 1, add a single hash (#) before the text. For heading 2, use ##, heading 3 use ###.

To bold text surround your text double asterixis (**). Italics are defined with a single underscore (_) before and after the words. Take a look:

Make sure the cell type has been changed to Markdown. When you run it, here’s what you get.

Raw NB Convert

This is a special cell type that is rarely used. It is used to convert the notebook file to another format.

Heading

This is used to change the heading of the cell but has now been deprecated. You can now use the Markdown cell type to write headings.

Using Shortcuts in Jupyter Notebook

Shortcuts can come in handy when working in Jupyter Notebook. Here are some of the default shortcuts you can use.

You can edit these shortcuts to suit your preferences.

Summary

Without doubt the Jupyter Notebook is the perfect tool if you are working on data science projects in Python. It can also be used for other Python projects not related to data science. As discussed in a previous article, an IDE is a tool in your programming toolbox and it’s to you to choose the right tool for the job. In this case, if data science is the job then Juypter Notebook is the right tool.

Hopefully this article has helped you to understand how to get Jupyter notebook up and running on your computer. We also discussed how to navigate and use the menus and icons in the notebook, how to write and run code, work with the Kernel, and write text with markdown. And, don’t forget that Jupyter Notebook works with a special kind of file format called IPYNB.

I hope you found this article helpful.

--

--