Introduction to Jupyter Notebooks

Overview:

Questions

  • What are Jupyter Notebooks?
  • Why are they useful?

Objectives

  • Start a new notebook
  • Add some markdown to your notebook

What are Jupyter Notebooks?

Jupyter notebooks are a way of running Python code (and other languages). The difference between using notebooks and an IDE like Spyder is that notebooks enable you to keep notes, images, equations etc. together with your code. They do this by using different types of 'cells'. The main types of cells are code cells and markdown cells. We'll cover these in more detail as we get to them.

Because you can keep notes etc. alongside your code, you can use Jupyter notebooks like a lab book. Just like when you're in the lab, it's important to write down what you're doing in your code and analysis; when you come back to a notebook at a later date with no recollection of what you did before, you'll thank your past self for making such clear notes.

Your First Notebook

Now we're going to get started with your first notebook.

The aim of these exercises is to get you familiar with the notebook interface. We'll be doing similar exercises to what you did in semester 1 so you can see the difference between working in Spyder and Notebooks.

Starting a new notebook

The first thing is to start a new notebook. There are a few different ways to do this depending on how your computer is set up. I'm going to assume that you have anaconda available, either through UniApps or installed on your own computer. If you need a refresher on how to install or access anaconda, Dr Davies has a video of how to do this in the Semester 1 Scientific Computing section on the PH10102 Moodle page.

  1. Open Anaconda Navigator
  2. You should see something similar to the screenshot below. Find the Jupyter Notebook application (not JupyterLab - this is a different thing) and click 'Launch'

launch-notebook.jpeg

If you see 'Install' rather than 'Launch', go ahead and press Install, then Launch.

  1. This should launch a new browswer window that looks something like the next screenshot. To start a new notebook, click 'New' then 'Python 3'.

start-new-notebook.jpg

  1. You should now be presented with a new blank notebook that looks something like this:

blank_notebook.jpg

Congratulations! You have your first Jupyter notebook!

The first thing we want to do is give the notebook a sensible file name. Click the filename 'Untitled' (just to the left of 'Last Checkpoint') and give your notebook a name.

Start a new notebook

If you haven't already, follow the instructions above to start a new notebook and rename it. You should also create a folder to keep all your work for this section of the course. Save your new notebook in this folder.

What next?

If you've got a new notebook started and set up a folder to keep all your work in, press 'Next' to move on to the next section. If you're having trouble getting notebooks started, ask for help on the PH10102 Scientific Computing group on Teams, or in the Friday support sessions.

In [ ]: