MLearning.ai
Published in

MLearning.ai

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

Jupyter Notebook Server starts

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.

Click the New button to create a Notebook

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

Notebook “Untitled1”

Notebook name

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

  • Click on “Untitled1”
Click on “Untitled1” to rename Notebook
  • This brings up the Rename Notebook dialog. Type a new name for your notebook.
Rename Notebook dialog
  • 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.

Menu bar

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.

Toolbar

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.

Code cell

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”
Example code in code cell and output

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.

Types of Notebook Cells

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.

Choosing cell type

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

Heading type no longer used

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
Change cell type to Markdown

# Heading

**bold text** not bold text

Add markdown to cell
  • Click Run from the toolbar
  • Markdown output shows up
Markdown output

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/.

--

--

--

Data Scientists must think like an artist when finding a solution when creating a piece of code. ⚪️ Artists enjoy working on interesting problems, even if there is no obvious answer ⚪️ linktr.ee/mlearning 🔵 Follow to join our 18K+ Unique DAILY Readers 🟠

Recommended from Medium

Verify sandbox in Deno

How To Create PWA Native Apps, And Why?

6 Essential Tips on How to Become a Full Stack Developer

Shared Lite: Developing a fully-baked app-less rental flow for everyone

Examples of Frequently Used Built-in Types and Packages in Go

Kubernetes Setup Using Kubeadm

Life is a journey of twists and turns, peaks and valleys, mountains to climb and oceans to explore.

Using Dockerized Jenkins REST API — PART 1

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Divya Sikka

Divya Sikka

Student

More from Medium

Draw Circle — Diameter, Radius, Arc and Segment Using Python Matplotlib Module

Top 9 Machine Learning Frameworks in Julia

A simple auto correct model using Python

Regularization Using Pipeline & GridSearchCV