Jupyter Notebook



What is Jupyter Notebook ?

 Jupyter

Jupyter

  • It is an open-source, web-based intuitively environment, which allows you to make and share records that contain live code, mathematical conditions, graphics, maps, plots, visualizations, and account content.
  • It coordinating with many programming dialects like Python, PHP, R, C#, etc.

Read Also

Advantages of Jupyter Notebook

  • All in one place
  • Easy to convert
  • Easy to share
  • Language independent
  • Interactive code

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

  • To install the Jupyter Notebook, to begin with, you would like to install the Python. You'll take after the below steps to download the Python.

Step 1

  • Click on this link to download the latest version of the Python.
 Install-1

Step 2:

  • Now, double tap on the downloaded file, the following window is opened. Select Install Now to Install Python.
 Install-2

Step 3:

  • You can see that installation is in process.
 Install-3

Step 4:

  • Once the installation is completed, the following window is open, you simply click on the close.
 Install-4
  • Once the Python installation is completed, follow the below steps to install the Jupyter Notebook with pip package.

Step 1:

  • Open the command prompt.

Step 2:

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

For Example:

Path= C:\Users\nisha\AppData\Local\Programs\Python\Python37\Scripts  

Step 3:

  • To upgrade the older version of pip, give the following command after the specified path
pip install --upgrade pip  

Step 4:

  • To install the Jupyter Notebook, type the below command:
pip install jupyter   
  • It takes a few seconds to install the Jupyter Notebook.

Step 5:

  • Once the installation process is completed.To run your notebook on the server using the following command in command prompt.
jupyter notebook

Jupyter notebook starts with the default web browser.

 Install-5

Dashboard of Jupyter Notebook

  • The following screenshot appears dashboard of the Jupyter Notebook which contains the three tabs.
 Dash

Jupyter Dashboard

Files Tab

  • It 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.
 Dash File

Files Tab

Running Tab

  • It is used to show currently running notebooks.
 Dash Running

Running Tab

Cluster Tab

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

Jupyter Cluster Tab

  • To make a new notebook, the notebook will be presented with the notebook title, menu bar, toolbar, and an empty code cell.
 User Interface

Jupyter User Interface

  • Notebook name: It is displayed at the top of the page, next to the Jupyter logo.
  • Menu bar: To presents different options that are used to manipulate the notebook functions.
  • Toolbar: It provides a quick way for performing the most-used operations within the notebook.
  • Code cell: It allows you to edit and write a new code.

Components of Jupyter Notebook

  • There are the following three components of Jupyter Notebook -
 Components

Components

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

Kernels

  • Kernels are the partitioned forms started by the scratch pad web application that's utilized to run a user's code within the given language and return yield to the notebook web application.
  • In Jupyter notebook kernel is available in the following languages:

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.
 Rename-1

Creating Notebook

  • Now, the new notebook opens in a new tab.
 Rename-2

Notebook Open

Read Also

Rename the Notebook

  • To rename the Notebook,
    • Double tap on the Untitled at the top of the screen.
    • A pop up window will open to renaming the file.
    • Enter a new notebook title that you simply need to include.
    • Then press on the Rename.
 Rename-3

Rename the Notebook

How to write and run a program in Jupyter

  • Now, you can run it by pressing the Shift+ Enter key or directly click on the run button at the top of the screen.
 Rename-4

Run Program in Jupyter

Types of Cells in Jupyter Notebook

  • There are the following four types of cells used in the Jupyter Notebook.
 Types-1

Types-1

1. Code Cell

  • The contents present in a code cell are 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.
  • Output can be presented in the form of text, image, matplotlib plots, or HTML tables.
 Types-2

Code Cell

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-3

Markdown Cell

Bold and Italics

  • To make text bold, write text between the double underscores or double asterisks.
 Types-4

Text bold in Jupyter

  • The output of the above code
 Types-5

Output

  • To make text italics, write text between single underscore or single asterisk.
 Types 6

Italics in Jupyter

  • The output of the above code
 Types 7

Italics in Jupyter Output

Headers

  • Creating headers in Markdown is 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.

Sample Code

 Types 8

Headers in Markdown

Output

 Types 9

Headers in Markdown output

Ordered Lists

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

Sample Code

 Types 10

Ordered Lists in Jupyter

Output

 Types 11

Ordered Lists in Jupyter Output

Bullet lists

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

Sample Code

 Types 12

Bullet Lists in Jupyter

Output

 Types 13

Bullet Lists in Jupyter Output

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 ().

Sample Code

 Types 14

Hyperlinks in Jupyter

Output

 Types 15

Hyperlinks in Jupyter Output

Table Content

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

Sample Code

 Types 16

Table Content

Output

 Types 17

Table Content Output

Images

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

Sample Code

 Types 18
  • Once the image is seen in the dashboard click on the Upload, you can see that image is uploaded in the dashboard.
 Types 19
  • Now, go to your current Notebook, and type the following code to insert the image
 Types 20

Current Notebook

  • The following image is inserted on the Notebook.
 Types 21

Inserted Image

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 22

Raw NBConvert Cell

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 window as given below.
 Types 23

Heading Cell

IPyWidgets in the Jupyter Notebook

  • The ipywidgets provides many common user interfaces for exploring code and data interactively.
  • IPywidgets are installed in Anaconda or you can also install it manually with conda.
 Ipywidget

Ipywidget

1. Text widget

  • The text widget allows the user to write the String.

Sample Code

from ipywidgets import widgets  
title_textbox = widgets.Text(  
    value = 'Hello Wikitechy',  
    description = 'Title:',  
)  
title_textbox

Output

 widget-1

Text Widget

2. Button widget

Sample Code

from ipywidgets import widgets  
button = widgets.Button(  
    description='Press Me',  
)  
button  

Output

 widget-2

Button Widget

3. Color picker

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

Sample Code

from ipywidgets import widgets  
color_picker = widgets.ColorPicker(  
    concise = True,  
    description = 'Background color:',  
    value = '#efefef',  
)  
color_picker

Output

 widget-3

Color Picker

  • When you click on the square box, the following color box will open.
 widget-4

Color Picker Box

4. Slider

  • Slider is used to find the range and interval between two entities

Sample Code

from ipywidgets import widgets  
range_slider = widgets.FloatRangeSlider(  
    value = [-2., +10.],  
    min = -5., max = +50., step = 0.1,  
    description = 'range:',  
    readout_format = '.1f',  
)  
range_slider

Output

 widget-5

Slider

Read Also

Sample Code

For add two numbers

from ipywidgets import widgets  
lb1 = widgets.Label('Enter the First number')  
display(lb1)  
text1 = widgets.Text()  
display(text1)  
lb2 = widgets.Label('Enter the Second number')  
display(lb2)  
text2 = widgets.Text()  
display(text2)  
btn = widgets.Button(description = "add")  
display(btn)  
lb3 = widgets.Label()  
display(lb3)  
def add(x):  
    a = int(text1.value)  
    b = int(text2.value)  
    lb3.value = 'result='+str(a+b)  
btn.on_click(add)  

Output:

 widget-6

Slider Output



Related Searches to Jupyter Notebook