Wednesday, December 25, 2024
Google search engine
HomeLanguagesGetting started with Jupyter Notebook | Python

Getting started with Jupyter Notebook | Python

The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations, and narrative text. Jupyter has support for over 40 different programming languages and Python is one of them. Python is a requirement (Python 3.3 or greater, or Python 2.7) for installing the Jupyter Notebook itself.

Jupyter Notebook can be installed by using either of the two ways described below:

Install Jupyter Notebook with Anaconda

Install Python and Jupyter using the Anaconda Distribution, which includes Python, the Jupyter Notebook, and other commonly used packages for scientific computing and data science. To install Anaconda, go through How to install Anaconda on Windows. and follow the instructions provided.

Install Jupyter Notebook Using PIP

Install Jupyter using the PIP package manager used to install and manage software packages/libraries written in Python. To install pip, go through How to install PIP on Windows? and follow the instructions provided.

Getting Started With Jupyter Notebook for Python

Command to Launch Jupyter Notebook

jupyter notebook

This will start up Jupyter and your default browser should start (or open a new tab) to the following URL: http://localhost:8888/tree

Screenshot-2023-08-24-at-41648-PM-(2)

When the notebook opens in your browser, you will see the Notebook Dashboard, which will show a list of the notebooks, files, and subdirectories in the directory where the notebook server was started. Most of the time, you will wish to start a notebook server in the highest level directory containing notebooks. Often this will be your home directory.

Creating a Jupyter Notebook

Now on the dashboard, you can see a new button at the top right corner. Click it to open a drop-down list and then if you’ll click on Python3, it will open a new notebook.

Screenshot-from-2023-08-25-18-24-23

Renaming Jupyter Notebooks

We can notice that at the top of the page is the word Untitled. This is the title for the page and the name of your Notebook. We can change the name by simply clicking on it.

Screenshot-from-2023-08-25-18-25-05

Run and Debug Jupyter Notebook Code Cell

Let’s try adding the following code to that cell:

Running a cell means that we want to execute the cell’s contents. To execute a cell, you can just select the cell and click the Run button that is in the row of buttons along the top. It’s towards the middle.

Screenshot-from-2023-08-25-18-25-52

Menu present in the Jupyter Notebook

Here is the list of all the items present in the menu:

  • File
  • Edit
  • View
  • Insert
  • Cell
  • Kernel
  • Widgets
  • Help

Starting Terminal

To open terminal go to the homepage and click on new and then select terminal from the drop down list.

Screenshot-from-2023-08-25-18-26-30

Viewing What’s Running

The home page of your Jupyter server (http://localhost:8888/tree) has two other tabs: Running and Clusters.

The Running tab will tell us which Notebooks and Terminals we are currently running. This is useful for when you want to shut down your server but you need to make sure that you have saved all your data. 

Screenshot-from-2023-08-25-18-26-57Useful Commands in Jupyter Notebook

Command to open a notebook in the currently running notebook server.

jupyter notebook notebook_name.ipynb

By default, the notebook server starts on port 8888. If port 8888 is unavailable or in use, the notebook server searches the next available port. You may also specify a port manually. In this example, we set the server’s port to 9999:

jupyter notebook --port 9999

Command to start the notebook server without opening a web browser:

jupyter notebook --no-browser

The notebook server provides help messages for other command line arguments using the –help flag:

jupyter notebook --help

Jupyter Notebook Shortcuts

To change modes(edit, command):

Esc - Change mode to command mode
Enter - Change mode to edit mode

To change content type(code or markdown) [in command mode]

m - Change to markdown
y - Change to code

To execute code or markdown [any mode]

Shift + Enter - Execute and go to next cell
Ctrl + Enter  - Execute and be in the same cell

To insert cell [in command mode]

a - Create cell in above to the cell
b - Create cell in below to the cell

To cut copy paste [in command mode]

x - Cut the cell that can be paste anywhere any number of times
c - Copy the cell that can be paste anywhere and any number of times
v - Paste the cell

Related Article: How to upload a dataset in Jupyter Notebook?

RELATED ARTICLES

Most Popular

Recent Comments