Javatpoint Logo
Javatpoint Logo

Jupyter Notebook Tutorial

Jupyter Notebook Tutorial

Jupyter Notebook tutorial provides basic and advanced concepts of the Jupyter Notebook. Our Jupyter Notebook tutorial is designed for beginners and professionals.

What is Jupyter Notebook?

Jupyter Notebook is an open-source, web-based interactive environment, which allows you to create and share documents that contain live code, mathematical equations, graphics, maps, plots, visualizations, and narrative text. It integrates with many programming languages like Python, PHP, R, C#, etc.

Note: Jupyter Notebook mainly used for Python because Python is used with Artificial Intelligence (AI), Machine learning, as well as Deep learning.

In this tutorial, we are going to discuss the following topics:


Advantages of Jupyter Notebook

There are the following advantages of Jupyter Notebook -

  1. All in one place: As you know, Jupyter Notebook is an open-source web-based interactive environment that combines code, text, images, videos, mathematical equations, plots, maps, graphical user interface and widgets to a single document.
  2. Easy to convert: Jupyter Notebook allows users to convert the notebooks into other formats such as HTML and PDF. It also uses online tools and nbviewer which allows you to render a publicly available notebook in the browser directly.
  3. Easy to share: Jupyter Notebooks are saved in the structured text files (JSON format), which makes them easily shareable.
  4. Language independent: Jupyter Notebook is platform-independent because it is represented as JSON (JavaScript Object Notation) format, which is a language-independent, text-based file format. Another reason is that the notebook can be processed by any programing language, and can be converted to any file formats such as Markdown, HTML, PDF, and others.
  5. Interactive code: Jupyter notebook uses ipywidgets packages, which provide many common user interfaces for exploring code and data interactivity.

Disadvantages of Jupyter Notebook

There are the following disadvantages of Jupyter Notebook:

  • It is very hard to test long asynchronous tasks.
  • Less Security
  • It runs cell out of order
  • In Jupyter notebook, there is no IDE integration, no linting, and no code-style correction.

Installation of Jupyter Notebook using pip package

To install the Jupyter Notebook, first, you need to install the Python. You can follow the below steps to download the Python.

Step1: Click on the link https://www.python.org/downloads/windows/ to download the latest version of the Python.

Installation of Jupyter Notebook using pip package

Step2: Now, double click on the downloaded file, the following window is opened. Select Install Now to Install Python.

Installation of Jupyter Notebook using pip package

Step3: You can see that installation is in process.

Installation of Jupyter Notebook using pip package

Step4: Once the installation is completed, the following window is open, you simply click on the close.

Installation of Jupyter Notebook using pip package

Once the Python installation is completed, follow the below steps to install the Jupyter Notebook with pip package.

Step1: Open the command prompt.

Step2: Copy/ set the path, where the Python script is presented.

For Example:

Note: If AppData is not visible, then go to View -> Options, select change folder, and search options. After clicking on the select change folder, click on the view, and select show hidden files, folders, and drives then click on the Apply -> OK.

Step3: To upgrade the older version of pip, give the following command after the specified path:

Step4: To install the Jupyter Notebook, type the below command:

It takes a few seconds to install the Jupyter Notebook.

Step5: Once the installation process is completed, you can run your notebook on the server using the following command in command prompt.

After a few seconds, Jupyter notebook starts with the default web browser which shows the list of all python files.

Installation of Jupyter Notebook using pip package

Dashboard of Jupyter Notebook

The below screenshot shows dashboard of the Jupyter Notebook which contains the three tabs.

Dashboard of Jupyter Notebook

Files Tab

The Files tab is used to display files and folders in the current directory. It also uses an Upload button through which a file can be uploaded to a notebook server.

Dashboard of Jupyter Notebook

Running Tab

The Running tab is used to show currently running notebooks.

Dashboard of Jupyter Notebook

Cluster Tab

IPython provides the Cluster Tab. IPython is a parallel computing framework, which is an extended version of the IPython kernel.

Dashboard of Jupyter Notebook

User interface of Jupyter Notebook

When you create a new notebook, the notebook will be presented with the notebook name, menu bar, toolbar, and an empty code cell.

User interface of Jupyter Notebook

Notebook name: Notebook name is displayed at the top of the page, next to the Jupyter logo.

Menu bar: The menu bar presents different options that are used to manipulate the notebook functions.

Toolbar: The toolbar provides a quick way for performing the most-used operations within the notebook.

Code cell: A code cell allows you to edit and write a new code.


Components of Jupyter Notebook

There are the following three components of Jupyter Notebook -

1. The notebook web application: It is an interactive web application for writing and running the code.

The notebook web application allows users to:

  • Edit code in the browser with automatic syntax highlighting and indentation.
  • Run code on the browser.
  • See results of computations with media representations, such as HTML, LaTex, png, pdf, etc.
  • Create and use JavaScript widgets.
  • Includes mathematical equations using Markdown cells.

2. Kernels: Kernels are the separate processes started by the notebook web application that is used to run a user's code in the given language and return output to the notebook web application.

In Jupyter notebook kernel is available in the following languages:

  • Python
  • Julia
  • Ruby
  • R
  • Scala
  • node.js
  • Go

3. Notebook documents: Notebook document contains a representation of all content which is visible in the notebook web application, including inputs and outputs of the computations, text, mathematical equations, graphs, and images.

Creating a Notebook

To create a Notebook in Jupyter, go to New and select Python3.

Creating a Notebook of Jupyter Notebook

Now, you can see that a new notebook opens in a new tab.

Creating a Notebook of Jupyter Notebook

Rename the Notebook

To rename the Notebook, double click on the Untitled at the top of the screen. A pop up window will open to renaming the file. Enter a new notebook name that you want to add. Then click on the Rename.

Creating a Notebook of Jupyter Notebook

How to write and run a program in Jupyter

After renaming the file, click on the first cell in the notebook to enter in the edit mode. Now you can write the code in working area. After writing the code, you can run it by pressing the Shift+ Enter key or directly click on the run button at the top of the screen.

How to write and run a program in Jupyter

Types of cells in Jupyter Notebook

There are the following four types of cells used in the Jupyter Notebook.

Types of cells in Jupyter Notebook

1. Code Cell

The contents present in a code cell is treated as statements in a programming language of the current kernel. By default, Jupyter notebook's kernel is in Python so you can write Python statements in a code cell. When you run the statement, its output is displayed below the code. Output can be presented in the form of text, image, matplotlib plots, or HTML tables.

Types of cells in Jupyter Notebook

2. Markdown Cell

Markdown cell provides documentation to the notebook and makes the notebook more attractive. This cell contains all types of formatting features such as making text bold and italic, headers, displaying ordered or unordered list, Bullet lists, Hyperlinks, tabular contents, images, etc.

To perform the following formatting features, first select Markdown cell from the drop-down menu.

Types of cells in Jupyter Notebook

Bold and Italics

  • To make text bold, write text between the double underscores or double asterisks.
Types of cells in Jupyter Notebook

The following screenshot shows the output of the above code.

Types of cells in Jupyter Notebook
  • To make text italics, write text between single underscore or single asterisk.
Types of cells in Jupyter Notebook

The following screenshot shows the output of the above code.

Types of cells in Jupyter Notebook

Headers

Creating headers in Markdown is quite similar to the creating headers in HTML. It displays text in 6 sizes. To make the text as a header, start the text using # symbol. The number of # symbols depends upon the size of the header.

For example -

Header 1 use one # symbol, header 2 use two # symbol, and so on.

Types of cells in Jupyter Notebook

The following screenshot shows the output of the above Header cells.

Types of cells in Jupyter Notebook

Ordered Lists

The ordered list starts with 1. Use tab to make the suborder followed by the order.

Types of cells in Jupyter Notebook

The following screenshot shows the output of the above Markdown data.

Types of cells in Jupyter Notebook

Bullet lists

In Jupyter notebook, if text starts with the dash (-) symbol, markdown cell coverts dash into a solid circle and asterisk (*) to a solid square.

Types of cells in Jupyter Notebook

The following screenshot shows the output of the above Markdown data.

Types of cells in Jupyter Notebook

Hyperlinks

Markdown cell allows you to attach the Hyperlink. To attach the hyperlink place the name of the link in square brackets [] and write link inside the parentheses ().

You can use the following code to insert the hyperlink.

Types of cells in Jupyter Notebook

Output:

Types of cells in Jupyter Notebook

Table Content

Markdown cell allows you to create a table using pipe symbol (|) and dash symbol (-). Pipe symbol (|) is used for making columns, and dash symbol (-) is used for making the rows.

The table creation is shown below:

Types of cells in Jupyter Notebook

The following screenshot shows the table content of markdown cell.

Types of cells in Jupyter Notebook

Images

To insert the image in a markdown cell, you first need to insert the image in the same directory. For this, go to Jupyter dashboard -> select Upload, specify the path of an image then click on Open.

Types of cells in Jupyter Notebook

Once the image is seen in the dashboard click on the Upload, you can see that image is uploaded in the dashboard.

Types of cells in Jupyter Notebook

Now, go to your current Notebook, and type the following code to insert the image.

Types of cells in Jupyter Notebook

The following screenshot shows that the image is inserted on the Notebook.

Types of cells in Jupyter Notebook

3. Raw NBConvert Cell

Raw NBConvert Cell provides a place where you can write output directly. These cells are not evaluated by the notebook kernel.

Types of cells in Jupyter Notebook

4. Heading Cell

The Jupyter Notebook does not support the heading cell. When you select the Heading from the drop-down menu, a pop will open on the screen which is shown in the below screenshot.

Types of cells in Jupyter Notebook

IPyWidgets in the Jupyter Notebook

The ipywidgets provides many common user interfaces for exploring code and data interactively.

By default, ipywidgets are installed in Anaconda or you can also install it manually with conda.

Some example of ipywidges are given below:

1. Text widget

The text widget allows the user to write the String:

Output:

IPyWidgets in the Jupyter Notebook

2. Button widget

The button widget is similar to the HTML button. To create button, type the following code.

Output:

IPyWidgets in the Jupyter Notebook

3. color picker

The Color picker allows you to select a color as per to your requirement.

Output:

IPyWidgets in the Jupyter Notebook

When you click on the square box, the following pop up will open.

IPyWidgets in the Jupyter Notebook

4. Slider

Sider is used to find the range and interval between two entities.

Output:

IPyWidgets in the Jupyter Notebook

Example: Write a code to add two numbers.

Output:

IPyWidgets in the Jupyter Notebook

Prerequisite

Before learning Jupyter Notebook, you must have the basic knowledge of HTML, CSS, and JavaScript.

Audience

Our Jupyter Notebook tutorial is designed to help beginners.

Problem

We assure that you will not find any problem in this Jupyter Notebook tutorial. But if there is any mistake or error, please post the error in the contact form.






Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA