Home and Learn: Data Analysis


Jupyter NoteBook Tutorial

A Jupyter Notebook is a great way to run Python and Pandas code as it means you don't have to install an IDE. In the previous lesson, we installed Jupyter on Windows. But the only reason we did so was because we'll need to load up some local datasets for this Pandas course. You can actually use the online of Jupyter version here (Jupyter Notebook link):

Jupyter Notebook

We have a Python course for beginners here:

Home and Learn Python Course

You can do a lot of the course through the Jupyter website, rather than installing PyCharm.

Let's see how Jupyter Notebooks work, though.

 

Getting Started with Jupyter Notebooks

Using your knowledge from the previous lesson, launch the Jupyter homepage. You should be looking at this:

The Jupyter Homepage in a browser

On the left, you'll see a list of folders, files and any Notebooks you create. Once you create a Notebook, you can reopen it by simply clicking its link on the left.

Top right of the homepage, click the button that says New. You'll see a dropdown list:

The new menu in Jupyter

Click on the Folder item. It might look like nothing has happened, but you should see a folder called Untitled Folder has been added to the list on the left. Select the folder by checking the box next to it. You'll see some icons appear top left:

File and folder list in the Jupyter root directory.

Click the Rename button. Name your folder Tutorials.

Click on the newly-renamed folder to be taken inside of it:

A new folder created in Jupyter.

Click on the New button again. From the menu, select the Python item:

Jupyter New file menu

Creating a new Python file will launch it in a new browser tab. It should look like this:

A new Jupyter Notebook

Notice that it says Untitled at the top. Left-click on the word Untitled and you'll see this box appear:

The rename notebook dialog box.

Type a new name for your Python file and click the Rename button. You should see your new title appear at the top in place of Untitled.

Click back on the Tutorials tab for a moment. You'll see your new Notebook in the folder:

A new notebook showing in the root folder of Jupyter.

If you accidentally close down your Getting Started tab, click on it here to reopen it.

Click back on your Getting Started tab. Let's add some code and run it.

 

Add Code to a Jupyter Notebook

Code in Jupyter Notebooks is added to cells. Cells are the grey areas that say In to the left of them. This is where you write your code.

Click inside of the cell. Add the following:

greeting = 'Hello Pandas!'
greeting

It should look like this:

Python code in a Jupyter Notebook cell.

To see the output of your code, you need to click the Run button, highlighted by a red arrow in the image above:

The output from code in a Jupyter cell.

Our Hello Pandas message is output below the cell. Notice that a new cell gets added whenever you Run your code.

You can add Python functions to cells and run them from another cell. To clarify this, add the following Python function to the cell below the first one:

def greetMe(myName):
    return 'Welcome to the lesson, ' + myName

A Python function in a Jupyter cell.

With your cursor inside of the greetMe function, click the Run button again. The only thing that will happen is that a new cell appears below the function. Add this in the empty cell:

greetMe('Kenny')

Calling the Python function

Run the third cell and you should see something like this output:

The output of the Python function.

You can cut cells, if you don't want them. Click inside the new empty cell. Type this:

'Cut this'

From then menu at the top, select Edit > Cut Cells. (Or just click the scissors icon.)

The Edit menu in Jupyter.

The cell should disappear.

To get a new cell, click inside cell 3, the one with the greetMe('Kenny') in it. From the Insert menu at the top of Jupyter, click Insert > Cell Below:

The Jupyter Insert menu.

You'll get a new cell:

A new cell from the Insert cell Menu in Jupyter.

 

OK, that's about it for this lesson. There's not much else to a Jupyter Notebook - they are pretty easy and intuitive to use. Let's move on to the first lesson on Data Analysis in Pandas.

Back to Pandas Contents Page

 


Email us: enquiry at homeandlearn.co.uk