How to use Jupyter notebook efficiently: 1.0
Let’s see the power of the Jupyter notebook…
In this blog, I am going to cover some basics of Jupyter notebook, its usage, and its power.
How to Start the Jupyter notebook?
I hope you are using Anaconda Prompt. If not, It is highly recommended to use Anaconda Distribution for the Data Science project.
Download Anaconda: Click Here
- Open anaconda prompt
- set the drive
- write the command
jupyter notebook
- hit Enter
It will open a Jupyter notebook server in your default browser at localhost:8888
.
Note: I was already using the default port localhost:8888
that is the reason It is trying to connect with another port.
A Jupyter notebook is an awesome tool in which you can:
- Write code
- Write some text
- Add images/videos/tables
- You can do almost everything that you do in HTML
means we can write the code and description also in the same notebook.
Let’s dive into it and create an iNTERACTIVE pyTHON nOTEbOOK(.ipynb) file.
How to create a notebook in Jupyter notebook?
- first, click to
New
button - second, In popped option, click
Python 3
It will create a new Untitled.ipynb
file.
- click on
Untitled
(underlined in the above image) to rename the notebook.
- Click the
Rename
button to finalize the newly entered name.
Understanding notebook(.ipynb) file in more detail
The Notebook consists of cells that you can add or/and delete according to your need.
Each cell can be executed in two different ways(generally):
- Markdown cell
- Code cell
Markdown cell:
Markdown is a text-to-HTML conversion tool and simply the superset of HTML. In Markdown cell you can write your text either in HTML format or standard Markdown format.
Code cell:
In which we write our code to be executed.
Let’s see the example below…
To execute any cell Hit Shift+Enter
.
In the above image, M is markdown cell and not executed till now.
Just go and click on the markdown cell and execute it…
Wow! You got this result…(below)
- Whenever you execute any cell, a new cell created automatically below to the executed cell. (as you can see in the above picture).
Wow, I hope you are convinced of the power of the Jupyter notebook.
Dive Deeper into the notebook
Let’s Dive Deeper into Markdown cell and How to use it?
First thing first, I hope you are familiar with HTML. If not, don’t worry we’ll not be using HTML to write our text, instead, we’ll use markdown style.
Headers:
There are six types of headers that you can write using #
in the markdown cell
just type #
and leave a space and write whatever you want as a header.
See the example below in the image.
- press
Shift+Enter
. you will get this result
Lists:
Unordered list:
to initialize Unordered list you can use either *
, +
, or —
with trailing space.
See the below example…
You can see in the above cell that nested elements are automatically colored differently.
Output:
Ordered List:
Output:
You can see that Jupyter notebook cares about all the nested list numbering.
Some more functionalities of the Jupyter notebook:
- For Bold text, use the text enclosed with two asterisks(**), no space should be there.
- For Italic/emphasized text, use only one asterisk(*), no space should be there.
For Block_quote/comment use
>
and the text further.
- I used
<hr>
tag for a horizontal breaking. - Instead of
<pre></pre>
of HTML you can type a tab and trail/successor text.
The Output of above markdown command:
Insert Image in the Jupyter notebook:
- Method 1: Copy any image from any source and paste the image to the markdown cell.
- Method 2: Copy the link of the image from the internet source and use
<img src="">
tag to showcase the image. Let’s see how?
How to play YouTube videos in the Jupyter notebook.
- Right-click on YouTube video→Copy embedded-code.
- In the code cell write
from IPython.display import HTML
. - use
HTML(Embedded_code)
, pass Embedded_code as a string. - run the code cell.
Let’s see how?
Well, suppose using all the above information you have written some notebook, right.
Now, you want to create a new notebook and want to copy the cells from the previous notebook and paste it into a newly created notebook.
Let’s see how?
How to copy and paste more than one cell into the Jupyter notebook among different notebooks?
Steps to copy more than one cell:
- Click on the cell you want to copy from and press
Esc
to make the notebook in command mode. When you will pressEsc
, below red-highlighted pencil will disappear. The sign of a pencil means the notebook is in Edit mode.
- press
Shift+arrow(up/down)
. - press
Ctrl+C
. - paste it wherever you want(It is also possible for different notebook also).
There are tons of things to explore in Jupyter notebook.
Just play with all the options.
Last Suggestion:
Play with the options, you will get more…
The keyboard shortcut is very helpful to save your lot of time.
Any Query? Comment below…