---
title: "**Jupyter Notebook Tutorial**"
source: Panaversity Learn Agentic AI
source_url: https://github.com/panaversity/learn-agentic-ai
licence: Apache-2.0
domain: agentic-ai
subdomain: panaversity-agentic
date_added: 2026-04-25
---

# **Jupyter Notebook Tutorial**

### **1. What is Jupyter Notebook?**

Jupyter Notebook is an open-source web application that allows you to create and share documents containing live code, equations, visualizations, and narrative text. It’s widely used for data cleaning and transformation, numerical simulation, statistical modeling, data visualization, machine learning, and much more.

### **2. Installing Jupyter Notebook**

Before you can start using Jupyter Notebook, you need to install it. There are several ways to install Jupyter Notebook:

#### **Option 1: Install via Anaconda (Recommended)**
Anaconda is a popular distribution of Python and R, which includes Jupyter Notebook along with many other useful packages for data science and machine learning.

1. **Download Anaconda:** Visit [Anaconda's official website](https://www.anaconda.com/products/distribution) and download the distribution suitable for your operating system.

2. **Install Anaconda:** Follow the installation instructions for your operating system.

3. **Launch Jupyter Notebook:** 
   - On Windows: Open Anaconda Navigator and launch Jupyter Notebook.
   - On Mac/Linux: Open a terminal and type `jupyter notebook`.

#### **Option 2: Install via pip**
If you already have Python installed, you can install Jupyter using pip.

1. **Open your terminal or command prompt.**
2. **Install Jupyter Notebook:**
   ```bash
   pip install notebook
   ```
3. **Launch Jupyter Notebook:**
   ```bash
   jupyter notebook
   ```

### **3. Starting Jupyter Notebook**

Once Jupyter Notebook is installed, you can start it by running the `jupyter notebook` command in your terminal or command prompt. This command will open Jupyter in your default web browser.

- **Navigating the Interface:**
  - **Notebook Dashboard:** The Jupyter dashboard is the main landing page where you can see all your files and notebooks in the current directory.
  - **Create a New Notebook:** Click on the "New" button on the right side and select "Python 3" (or another Python version) to create a new notebook.

### **4. Jupyter Notebook Basics**

#### **4.1. Notebook Structure**

A Jupyter Notebook is composed of cells. There are mainly two types of cells:
- **Code Cells:** Where you write your Python code.
- **Markdown Cells:** Where you can write text, including explanations, notes, or formatted content using Markdown.

#### **4.2. Running Code**

1. **Code Cells:**
   - You can write Python code in these cells and execute it by pressing `Shift + Enter`.
   - For example, try typing the following in a code cell and run it:
     ```python
     print("Hello, Jupyter!")
     ```
   - The output will appear right below the code cell.

2. **Markdown Cells:**
   - Markdown cells are used for writing formatted text, such as headings, lists, and links.
   - To create a Markdown cell, change the cell type from "Code" to "Markdown" using the dropdown menu in the toolbar.
   - For example, type the following Markdown and run the cell:
     ```markdown
     # This is a Heading
     This is some text in **bold** and *italic*.
     ```
   - The text will be formatted accordingly.

#### **4.3. Keyboard Shortcuts**
Jupyter has many useful keyboard shortcuts to speed up your workflow. Here are a few essential ones:

- **Run a cell:** `Shift + Enter`
- **Insert a new cell below:** `B`
- **Insert a new cell above:** `A`
- **Convert a cell to code:** `Y`
- **Convert a cell to Markdown:** `M`
- **Delete a cell:** `D + D` (press `D` twice)
- **Undo cell deletion:** `Z`

### **5. Working with Data**

Jupyter Notebooks are great for working with data. Here’s a simple example of loading and visualizing data using Python libraries like pandas and matplotlib.

1. **Install Required Libraries:**
   If you haven't installed pandas or matplotlib, you can do so using pip:
   ```bash
   pip install pandas matplotlib
   ```

2. **Load and Display Data:**
   ```python
   import pandas as pd

   # Load a dataset (for example, an inbuilt dataset)
   data = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')

   # Display the first few rows of the dataset
   data.head()
   ```

3. **Visualize Data:**
   ```python
   import matplotlib.pyplot as plt

   # Create a simple scatter plot
   plt.figure(figsize=(8, 6))
   plt.scatter(data['sepal_length'], data['sepal_width'])
   plt.title('Sepal Length vs Sepal Width')
   plt.xlabel('Sepal Length')
   plt.ylabel('Sepal Width')
   plt.show()
   ```

### **6. Saving and Exporting Notebooks**

You can save your notebook by clicking the save icon (disk icon) or by pressing `Ctrl + S`. Jupyter Notebooks are saved with the `.ipynb` extension.

You can also export your notebook to different formats, such as HTML, PDF, or a Python script. To do this:

1. **Go to File > Download as.**
2. **Choose the desired format (e.g., HTML, PDF, .py).**

### **7. Advanced Features**

#### **7.1. Magic Commands**
Jupyter Notebooks include "magic commands" that simplify common tasks. Some useful magic commands include:

- **%timeit:** Time the execution of a single line of code.
  ```python
  %timeit sum(range(1000))
  ```
- **%%time:** Time the execution of an entire cell.
  ```python
  %%time
  sum(range(1000))
  ```

- **%matplotlib inline:** Display matplotlib plots directly in the notebook.
  ```python
  %matplotlib inline
  ```

#### **7.2. Widgets**
Jupyter Notebooks support interactive widgets that can enhance the user experience. You can create sliders, buttons, and other UI elements using the `ipywidgets` library.

Install the library:
```bash
pip install ipywidgets
```

Example of a simple slider:
```python
import ipywidgets as widgets
from IPython.display import display

slider = widgets.IntSlider(min=0, max=10, value=5)
display(slider)
```

#### **7.3. Extensions**
Jupyter Notebook has various extensions that can be added to improve functionality. The **Jupyter Nbextensions** is a popular collection of extensions.

Install Nbextensions:
```bash
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
```

After installation, you can access the Nbextensions tab in the Jupyter dashboard to enable and configure extensions.

### **8. Best Practices**

- **Document your code:** Use Markdown cells to explain what your code does, making it easier for others (and yourself) to understand.
- **Organize your notebook:** Use headings and sections to keep your notebook well-structured.
- **Version control:** Store your notebooks in a Git repository to track changes and collaborate with others.
- **Backup your work:** Regularly save and backup your notebooks to avoid losing work.

### **9. Conclusion**

Jupyter Notebooks are a powerful tool for prototyping, exploring, and sharing Python code, especially in the context of data science and machine learning. They combine the interactivity of writing code and seeing the results immediately with the ability to document and share your findings. With the basics covered in this tutorial, you should be well on your way to leveraging Jupyter Notebooks for your projects.
