How To Work With Jupyter Notebook

Share this post

How to use Jupyter Notebook

(Step-by-step)

This post is part of the complete Guide on Python for SEO

This is not a tutorial on how to use Python. I consider that you already know how to use Python. If not, just read my guide to help you learn Python for SEO, Data Science or Programming.

Know that Jupyter is not the only option that you can use to run Python, you could also use an IDE like Spyder, or using IPython with a simple Text Editor.

This post is part of the complete Guide on Python for SEO

Why Use Jupyter Notebook?

A Python Notebook, like Jupyter Notebook, is the perfect trial and error tool. Jupyter Notebook is an open-source environment that lets you write, read and share your Python code for data analysis.

How To Install Jupyter Notebook?

If you have never installed Python, you should probably install Python using Anaconda.

Anaconda is the perfect Data Science Distribution of Python.

By installing Jupyter Notebook using Anaconda, you’ll also install:

  • Python
  • Useful Data Science libraries: Matplotlib, SciPy, Pandas, Numpy
  • Spyder IDE
  • Jupyter Notebook

Launch Jupyter Notebook

Now that you have installed Jupyter Notebook using Anaconda, all you need to do to launch Jupyter on Windows is to get the program through your windows navigator.

Launch Jupyter Notebook

How To Use Jupyter Notebook

We have installed and launched Jupyter Notebook.

Now, how to use it?

I will show you a step-by-step tutorial to help you use this amazing tool to start coding with Python.

Create a Notebook

The first step is to create a Notebook.

Click New > Python 3

Create a Notebook in Jupyter
Create a Notebook in Jupyter

Next step is to give a name to your Notebook.

Give a Name to your Notebook
Give a Name to your Notebook
Jupyter Tutorial
Jupyter Tutorial

Use The Jupyter Console

To start using the console is really simple. All you have to do is type in any Python command in the console.

This is the equivalent of using the IPython Console in Spyder.

With this tool, you are going to prompt any command line-by-line.

Let’s build a “Hello World” function.

Function in Jupyter Notebook
Create a Hello World Function in Jupyter

To run the code, just press Shift+Enter on your keyboard.

If you understand nothing of the code above, just refer to my guide on Python cited at the beginning of this post.

Create a Python Script in The Notebook

What we just did is only going to be accessibile via the notebook we created.

To build a variable that you can get from many notebooks, we will need to build a Script in a seperate file.

To do this, we are going to create a script instead of a Notebook, like we did in the previous section.

Python script in Jupyter
Python Script in Jupyter
  1. Navigate to the home page clicking the Jupyter logo on top left.
  2. Click “New”
  3. Click “Text Files”
  4. Click to change the name
  5. Change to extension .txt to .py
  6. Click “OK”
  7. Write your first Function
Write First Script in Jupyter Notebook
Write First Script in Jupyter Notebook

Import a Function From Your Predefined Script

Here, we have defined a function called my_function() in a script called my_first_script.py.

To use it, let’s go back to our “Jupyter Tutorial” Notebook.

  1. Import the function from the script using from and import keywords.
  2. Call the function by its name.
from my_first_script import my_function, my_function()
Import the function you created using From and Import

Use Markdown to Write Text in Jupyter Notebook

This is actually a pretty cool function tha I don’t use enough. You can use Markdown in Jupyter Notebook to write some text in between your code.

This is the perfect storytelling tool to help make your code memorable for later use.

Open Markdown

Using Markdown is quite simple.

Go to Cell > Cell Type > Markdown

Open Markdown in Jupyter Notebook

Write Text in Markdown

To write text in Markdown, just use this quick cheatsheet.

# This is a H1
## This is a H2
### This is a H3
###### This is a H6

*italic*

**bold**

> Quote

* Unordered List
* Unordered List
 * Unordered subList
 * Unordered subList
 
1. Ordered List
2. Ordered List
3. Ordered List

![Image](https://www.jcchouinard.com/wp-content/uploads/2019/07/how-to-rank-your-linkedinpage.jpg)

[jcchouinard.com](https://www.jcchouinard.com)

For more ideas, just read this post on Github.

At last, you can now start using Jupyter Notebook to run your Python Scripts. Let’s find out how to use Python for DataScience and Python for SEO.