Jupyter Notebook Tutorial

What is Jupyter Notebook?

Jupyter Notebook is an interactive web-based environment for writing and running code, primarily used for data analysis, scientific computing, and machine learning. It allows you to:

Installation

1Install Anaconda (Recommended for Beginners)

Anaconda includes Jupyter Notebook and many useful Python packages.

  1. Go to https://www.anaconda.com/download
  2. Download the installer for your operating system (Windows, Mac, or Linux)
  3. Run the installer and follow the installation wizard
  4. Accept the default settings

2Alternative: Install with pip

If you already have Python installed, you can install Jupyter using pip:

pip install notebook

🚀 Launching Jupyter Notebook

1Launch from Anaconda Navigator

Open Anaconda Navigator and click the "Launch" button under Jupyter Notebook.

Description of the image

2Launch from Command Line/Terminal

Open your terminal (or Anaconda Prompt on Windows) and type:

jupyter notebook

This will open Jupyter in your default web browser.

Tip
Navigate to the folder where you want to create notebooks before launching Jupyter. Use cd command to change directories.

🖥️ The Jupyter Interface

Description of the image

The dashboard shows:

📝 Creating Your First Notebook

1Create a New Notebook

  1. Click the "New" button in the top right
  2. Select "Python 3" (or your preferred kernel)
  3. A new notebook will open in a new browser tab

2Rename Your Notebook

Click on "Untitled" at the top and type a new name, then press Enter.

Description of the image

🔲 Understanding Cells

Notebooks are made up of cells. There are two main types:

1. Code Cells

Used for writing and executing Python code.

Description of the image

2. Markdown Cells

Used for writing formatted text, explanations, and documentation.

Description of the image

▶️ Running Cells

Three Ways to Run a Cell:

  1. Shift + Enter: Run cell and move to the next cell
  2. Ctrl + Enter: Run cell and stay on the same cell
  3. Alt + Enter: Run cell and insert a new cell below
Description of the image
⚠️ Important
Cells can be run in any order, but variables from previous cells must be run first to be available in later cells.

⌨️ Essential Keyboard Shortcuts

Jupyter has two modes:

Edit Mode (Green border around cell)

You're typing inside a cell. Press Esc to exit.

Command Mode (Blue border around cell)

You're navigating between cells. Press Enter to edit a cell.

Shortcut Action
Shift + Enter Run cell and select below
Ctrl + Enter Run cell
A (command mode) Insert cell above
B (command mode) Insert cell below
D D (press D twice) Delete selected cell
M (command mode) Change to markdown cell
Y (command mode) Change to code cell
Ctrl + S Save notebook
H (command mode) Show all keyboard shortcuts

📊 Practical Example

Description of the image

✨ Advanced Features

Magic Commands

Special commands that start with %

%timeit sum(range(100))
%matplotlib inline
%pwd # Print working directory

Tab Completion

Press Tab to autocomplete variable names and see available methods.

df.h [Tab]
# Shows: head(), hist(), etc.

Help & Documentation

Add ? after a function to see its documentation.

print?
# Shows print function docs

Shell Commands

Run system commands with !

!pip install numpy
!ls # List files
!pwd # Print directory

💾 Saving and Sharing

1Auto-save

Jupyter auto-saves your work periodically. You'll see "Last Checkpoint" at the top.

2Manual Save

Press Ctrl + S or click the save icon.

3Export Formats

Go to File → Download as to export your notebook:

  • HTML: Share as a webpage
  • PDF: Print or share as document
  • Python (.py): Extract just the code
  • Markdown: Plain text with formatting

🎯 Best Practices

📝 Organization
  • Use markdown cells to explain what your code does
  • Break code into small, logical cells
  • Use descriptive variable names
  • Add comments in your code
🔄 Workflow
  • Run cells from top to bottom when starting
  • Restart kernel if variables get confusing: Kernel → Restart
  • Clear output regularly: Cell → All Output → Clear
  • Save frequently!
🐛 Debugging
  • If stuck, restart the kernel and run all cells
  • Check cell numbers - they show execution order
  • Use print() statements to debug
  • Read error messages carefully - they tell you what went wrong

🚨 Common Issues & Solutions

Problem Solution
Cell shows [*] and won't finish Interrupt the kernel: Kernel → Interrupt
Variables not found Run previous cells that define those variables
Package not found Install it: !pip install package_name
Notebook won't open Check if Jupyter is running, restart the server
Changes not saving Check "Last Checkpoint" time, manually save

🎓 Next Steps

Now that you know the basics, try these:

  1. Practice: Create a notebook and experiment with Python code
  2. Learn Libraries: Explore pandas, numpy, matplotlib
  3. Try Projects: Analyze a dataset, create visualizations
  4. Explore Extensions: Install Jupyter extensions for more features
  5. JupyterLab: Try the next-generation interface with jupyter lab

📚 Additional Resources

🎉 You're Ready to Go!

Start experimenting with Jupyter Notebook and have fun coding!