0% found this document useful (0 votes)
2 views

Jupyter Notebook Tutorial

Unit 3 covers the use of Jupyter Console and Jupyter Notebook for data manipulation and visualization, including data uploading, streaming, and accessing various file formats. It discusses the advantages and disadvantages of Jupyter Notebook, installation steps, and its user interface components. Additionally, it highlights the types of cells in Jupyter Notebook and the use of ipywidgets for interactive data exploration.

Uploaded by

mohdrahib.2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Jupyter Notebook Tutorial

Unit 3 covers the use of Jupyter Console and Jupyter Notebook for data manipulation and visualization, including data uploading, streaming, and accessing various file formats. It discusses the advantages and disadvantages of Jupyter Notebook, installation steps, and its user interface components. Additionally, it highlights the types of cells in Jupyter Notebook and the use of ipywidgets for interactive data exploration.

Uploaded by

mohdrahib.2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Unit 3

Getting Your Hands Dirty With Data

Understanding the tools:


Using the Jupyter Console, Interacting with screen text, Changing the
window appearance, Getting Python help, Getting IPython help, Using
magic functions, Discovering objects,
Using Jupyter Notebook, Working with styles, Restarting the kernel,
Restoring a checkpoint, Performing Multimedia and Graphic Integration,
Embedding plots and other images, Loading examples from online sites,
Obtaining online graphics and multimedia.

Working with Real Data:


Uploading, Streaming, and Sampling Data,
- Uploading small amounts of data into memory,
- Streaming large amounts of data into memory, Generating variations
on image data,
- Sampling data in different ways,
Accessing Data in Structured Flat-File Form ,
- Reading from a text file
- Reading CSV delimited format,
- Reading Excel and other Microsoft Office files,
Sending Data in Unstructured File Form,
Managing Data from Relational Databases,
Interacting with Data from NoSQL Databases,
Accessing Data from the Web.

Jupyter Console

Jupyter Notebook

https://www.javatpoint.com/jupyter-notebook
What’s the difference between JupyterLab and Jupyter
Notebook?
While both Jupyter lab and Notebook support programming languages such as Python,
Julia, Scala, and R, support for all these languages come preinstalled with Jupyter lab.

Jupyter notebook only offers a very simple interface using which users can open
notebooks, terminals, and text files.

Jupyter lab offers a very interactive interface that includes notebooks, consoles,
terminals, CSV editors, markdown editors, interactive maps, and more. In the Jupyter
lab, notebooks also have a few improvements like the drag and drop cells feature which
is not available in the Jupyter notebook. Overall, JupyterLab can be considered as an
extension to Jupyter notebook to increase its scope.

Ipython

https://www.tutorialspoint.com/jupyter/ipython_introduction.htm

Ipython Magic Functions

https://ipython.readthedocs.io/en/stable/interactive/magics.html

https://www.tutorialspoint.com/jupyter/ipython_magic_commands.htm

https://problemsolvingwithpython.com/02-Jupyter-Notebooks/02.06-Magic-
Commands/

Jupyter Notebook https://www.javatpoint.com/jupyter-notebook

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:

o Advantages of Jupyter Notebook


o Disadvantages of Jupyter Notebook
o Installation of Jupyter Notebook
o The Dashboard of Jupyter Notebook
o User interface of Jupyter Notebook
o Components of Jupyter Notebook
o Creating a Notebook in Jupyter Notebook
o Types of cells in Jupyter Notebook
o ipywidgets in the Jupyter Notebook

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:

o It is very hard to test long asynchronous tasks.


o Less Security
o It runs cell out of order
o 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.
Step2: Now, double click on the downloaded file, the following window is opened.
Select Install Now to Install Python.
Step3: You can see that installation is in process.

Step4: Once the installation is completed, the following window is open, you simply click on
the close.
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:

1. Path= C:\Users\Manya\AppData\Local\Programs\Python\Python37\Scripts

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:

1. pip install --upgrade pip

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

1. pip install jupyter

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.
1. jupyter notebook

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

Dashboard of Jupyter Notebook


The below screenshot shows dashboard of the Jupyter Notebook which contains
the three tabs.
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.

Running Tab

The Running tab is used to show currently running notebooks.

Cluster Tab

IPython provides the Cluster Tab. IPython is a parallel computing framework, which is an
extended version of the IPython kernel.
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.

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:

o Edit code in the browser with automatic syntax highlighting and indentation.
o Run code on the browser.
o See results of computations with media representations, such as HTML, LaTex, png, pdf, etc.
o Create and use JavaScript widgets.
o 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:

o Python
o Julia
o Ruby
o R
o Scala
o node.js
o 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.
Now, you can see that a new notebook opens in a new tab.

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

Types of cells in Jupyter Notebook


There are the following four types of cells used in the 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.

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.
Bold and Italics

o To make text bold, write text between the double underscores or double asterisks.

The following screenshot shows the output of the above code.

o To make text italics, write text between single underscore or single asterisk.

The following screenshot shows the output of the above code.

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.
The following screenshot shows the output of the above Header cells.

Ordered Lists

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

The following screenshot shows the output of the above Markdown data.
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.

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

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.


Output:

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:

The following screenshot shows the table content of markdown cell.

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.
Once the image is seen in the dashboard click on the Upload, you can see that image is
uploaded in the dashboard.

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

The following screenshot shows that the image is inserted on the 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.

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.

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:

1. from ipywidgets import widgets


2. title_textbox = widgets.Text(
3. value = 'Hello World',
4. description = 'Title:',
5. )
6. title_textbox

Output:

2. Button widget

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

1. from ipywidgets import widgets


2. button = widgets.Button(
3. description='Press Me',
4. )
5. button

Output:

3. color picker

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

1. from ipywidgets import widgets


2. color_picker = widgets.ColorPicker(
3. concise = True,
4. description = 'Background color:',
5. value = '#efefef',
6. )
7. color_picker

Output:

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

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

1. from ipywidgets import widgets


2. range_slider = widgets.FloatRangeSlider(
3. value = [-2., +10.],
4. min = -10., max = +20., step = 0.1,
5. description = 'range:',
6. readout_format = '.1f',
7. )
8. range_slider

Output:

Example: Write a code to add two numbers.

1. from ipywidgets import widgets


2. lb1 = widgets.Label('Enter the First number')
3. display(lb1)
4. text1 = widgets.Text()
5. display(text1)
6. lb2 = widgets.Label('Enter the Second number')
7. display(lb2)
8. text2 = widgets.Text()
9. display(text2)
10. btn = widgets.Button(description = "add")
11. display(btn)
12. lb3 = widgets.Label()
13. display(lb3)
14. def add(x):
15. a = int(text1.value)
16. b = int(text2.value)
17. lb3.value = 'result='+str(a+b)
18. btn.on_click(add)

Output:

You might also like