Getting started with Jupyter Notebook | Python

Author: neptune | 28th-Aug-2022
#Pip

To get started, you must open up your terminal and go to a folder of your choice. If you are using it for the first time, you need to install the Jupyter Notebook.



Follows below steps:

1. Installing Jupyter Notebook using PIP

All you need to do is run below two cmd’s and you are done.


>>> python3 -m pip install --upgrade pip


>>> python3 -m pip install jupyter



2. Steps to run the Jupyter notebook

Follow the below steps to run the Jupyter notebook :
Step #1: After successfully installing run ‘jupyter notebook’ in the terminal/command prompt. 

Copy the host and open in the browser sometimes it automatically opens the browser.
Sample Host : http://localhost:8888/ ?token=53fea43ac1826478


Step #2: On the top left corner, click the new button and select python3 (ipykernel). 

This will open a new notebook tab in your browser.


Step #3: Press Enter or click on the first cell in your notebook to go into edit mode.



Step #4: Now you are free to write any code.


Step #5: You can run your code by pressing Shift + Enter or the run button provided at the top.

An example code is given below:

If you are running it the first time then you may get “ModuleNotFoundError” then you need to install the Pandas Module along with Wheel.


I fixed this using the below commands in Ubuntu...

Type python on your terminal. If you see python version 2.x, then run these two commands to install Pandas:

>>>sudo python -m pip install wheel

>>>sudo python -m pip install pandas

Else if you see python version 3.x, then run these two commands to install Pandas:

>>>sudo python3 -m pip install wheel

>>>sudo python3 -m pip install pandas


This will resolve that “ModuleNotFoundError” Now enjoy Jupyter !!!


Tips and Tricks to use Jupyter Notebook

To make your life easy with Jupyter Notebook look into the below commands.

1. To Change Port: By default, it starts on port 8888 in case it is unavailable or in use you can also specify a port manually. 

For example:
>>> jupyter notebook --port 9999


2. To change modes (edit, command):
Esc - Change mode to command mode.

Enter - Change mode to edit mode.


3. To change content type (code or markdown) [in command mode]
m - Change to markdown

y - Change to code

Highlighted text is the Markdown cell.


4. To execute code or markdown [any mode]
Shift + Enter - Execute and go to next cell.

Ctrl + Enter  - Execute and be in the same cell.


5. To insert cell [in command mode]
a - Create cell in above to the cell.

b - Create cell in below to the cell.


6. To cut copy paste [in command mode]
x - Cut the cell.

c - Copy the cell.

v - Paste the cell.


7. To capture the execution time

%%time 

If you have any questions, or simply would like to share your thoughts, then feel free to reach out in the comments section below.





Related Blogs
Best Python package manager and package for virtual environment ?
Author: neptune | 18th-Jun-2023
#Python #Pip
We will explore the options of Pip, Virtualenv, Anaconda, and also introduce Pyenv as a helpful tool...

View More