Jupyter Notebook — Part1
How to use Jupyter Notebook
What is Jupyter Notebook ?
Jupyter Notebook is a free and open-source web application which allows you to add and execute code, see the interactive output, add text (equations, rich text, plots etc.) and share the notebook easily with others.
It allows you to run and edit notebook documents using a web browser. You can run it locally on your desktop without internet access or accessed using the internet from a remote server.
How is it used?
Jupyter Notebooks is widely used by data scientists as a tool for data analysis.
Some uses include:
- Data cleaning and transformation
- Data visualization
- Data exploration
- Statistical modeling
Jupyter supports over 40 programming languages, including Python, R, Julia and Scala.
Installation
Jupyter Notebook can be installed using one of the following methods:
Using pip
pip is the package manager tool that comes with a Python install.
In Command Prompt (Windows) or Terminal (Mac), run
pip install jupyter
Using conda
Conda is the package manager tool that comes with a conda install. Anaconda is a Python and R distribution that also includes data science packages and Jupyter Notebook.
Run Jupyter Notebook
To run the notebook, run the following command at the Terminal (Mac) or Command Prompt (Windows):
jupyter notebook
Note: If the above command fails to start jupyter on Windows, run the following command:
python -m notebook
This starts the Jupyter notebook server. Your default browser will open a new tab with the URL: http://localhost:8888/tree

Now that the notebook server is running, let’s create a notebook.
Create a notebook
Click on New to open the list of options to choose from. I have Python3 installed, so I chose Python3 to create a notebook.

This will open a new browser tab with your newly created Notebook.

Notebook name
Note that the Notebook created is called “Untitled1” by default. Let’s rename it to be more descriptive.
- Click on “Untitled1”

- This brings up the Rename Notebook dialog. Type a new name for your notebook.

- Click Rename button on the Rename Notebook dialog.
Menu and Toolbar
The menu provides regular options to control the Notebook functions. Example: Click Insert -> Insert Cell Above to insert a cell above the default cell in the notebook.

The Toolbar provides a way to quickly access most used options on a Notebook. Example: Clicking on the ‘+’ icon adds another cell to the notebook.

Notebook cells
Code cells
The default cell added to the notebook is a code cell. You can type and run code in your notebook’s code cells. Since we created our Notebook with Python3 kernel, we can write Python code in the code cells.

Let’s add some code and run it.
- Type print(“Test”) in the code cell
- From the Toolbar, click Run to execute the code
- Note the output “Test”

If you have multiple codes cells, you can select a particular cell and Run it to execute that particular code. You can also run all the code cells in order to share variables and run the code like a program.
Other types of cells
You can add other types of cells to your notebook.

Markdown cells — Type text is rendered as HTML and serves as explanatory text. This allows you to use the Notebook as instructional/educational material.
Raw NBConvert cells — content in the raw cells are not evaluated by the notebook. The content in the raw cells will pass through the command line tool nbconvert unmodified and render in the format intended (HTML, LaTeX etc).
You can also choose to set the cell type from the toolbar as follows. The default cell type is code.

Note it shows a cell type as Heading, but it is no longer supported. You will get the following dialog if you choose Heading type

For our purposes, we will mostly use Code cells and Markdown cells.
Jupyter Notebook supports markdown which is a markup language. You can use markdown cells to add supportive explanatory text to your Notebook.
Adding Markdown
- Click + icon on the toolbar to add a cell. Default cell type is Code
- Change cell type to Markdown from the toolbar dropdown

- Add the following markdown to the cell (here is a markdown cheatsheet)
# Heading
**bold text** not bold text

- Click Run from the toolbar
- Markdown output shows up

Resources
Divya Sikka is a Student Ambassador in the Inspirit AI Student Ambassadors Program. Inspirit AI is a pre-collegiate enrichment program that exposes curious high school students globally to AI through live online classes. Learn more at https://www.inspiritai.com/.