Jupyter Notebook – Getting started

Uncategorized


0) Notebook basics (must know)

  1. Run cell: Shift + Enter
  2. Run and insert new cell below: Alt + Enter
  3. Command mode vs Edit mode: Esc (command), Enter (edit)
  4. Add cell below/above: B / A (command mode)
  5. Change cell type: M (Markdown), Y (Code)
  6. Delete cell: DD (press D twice)
  7. Move cell: J/K select then Ctrl + Shift + ↑/↓ (or cut/paste)

A) Python essentials inside Notebook (1–15)

1) Confirm Python environment

import sys, platform
print(sys.version)
print(platform.platform())
print(sys.executable)

2) Install a package (inside notebook)

%pip install requests

3) Check installed packages quickly

%pip list

4) See current working folder

import os
os.getcwd()

5) List files

import os
os.listdir(".")

6) Create folders safely

from pathlib import Path
Path("data").mkdir(exist_ok=True)

7) Read a text file

from pathlib import Path
Path("sample.txt").write_text("hello jupyter\nline2")
print(Path("sample.txt").read_text())

8) Timing a single line

%time sum(range(10_000_00))

9) Timing a whole cell

%%time
total = 0
for i in range(2_000_000):
    total += i
total

10) Measure memory (if installed)

%pip install memory_profiler
%load_ext memory_profiler
%memit [i*i for i in range(300_000)]

11) Quick help for any function

len?

12) Docstring + signature

help(str.split)

13) Pretty print complex objects

from pprint import pprint
pprint({"a":[1,2,3], "b":{"x":10,"y":20}})

14) Rich display (HTML)

from IPython.display import HTML
HTML("<h3 style='color:green'>Hello from HTML</h3>")

15) Display Markdown from code

from IPython.display import Markdown
Markdown("### This is generated **Markdown** from Python")

B) Markdown mastery (16–22)

16) Markdown template (copy into a Markdown cell)

# Title
## Section
- bullet
- bullet

**bold**, *italic*, `inline code`

> blockquote

[link text](https://example.com)

17) Tables in Markdown

| Name | Score |
|------|------:|
| Raj  |  98   |
| Asha |  87   |

18) LaTeX math (Markdown cell)

Inline: $E=mc^2$

Block:
$$
\sum_{i=1}^{n} i = \frac{n(n+1)}{2}
$$

19) Collapsible sections (Markdown cell)

<details>
  <summary>Click to expand</summary>

  Hidden details here.

</details>

20) Add images from file (Markdown cell)

![My Image](./path/to/image.png)

21) Add emojis ✅🔥📌

Learning Jupyter is fun ✅🔥

22) Use “TOC” style headings (habit tip)

Use consistent headings: #, ##, ### so notebooks stay readable.


C) Data analysis superpowers (23–35)

23) Install core data stack

%pip install numpy pandas matplotlib

24) Make a DataFrame

import pandas as pd
df = pd.DataFrame({"name":["A","B","C"], "score":[88,92,79]})
df

25) Filter rows

df[df["score"] >= 90]

26) Describe statistics

df["score"].describe()

27) Add a new column

df["passed"] = df["score"] >= 80
df

28) Save to CSV

df.to_csv("scores.csv", index=False)

29) Load from CSV

pd.read_csv("scores.csv")

30) Basic plot

import matplotlib.pyplot as plt
df.plot(kind="bar", x="name", y="score")
plt.show()

31) Histogram

df["score"].plot(kind="hist", bins=5)
plt.show()

32) Read JSON

import json
data = {"users":[{"name":"A","age":30},{"name":"B","age":26}]}
Path("users.json").write_text(json.dumps(data))
pd.json_normalize(json.loads(Path("users.json").read_text())["users"])

33) Quick pivot

sales = pd.DataFrame({
    "city":["Tokyo","Tokyo","Osaka","Osaka"],
    "product":["A","B","A","B"],
    "amount":[10,14,8,11]
})
sales.pivot(index="city", columns="product", values="amount")

34) Groupby

sales.groupby("city")["amount"].sum()

35) Missing values

import numpy as np
d = pd.DataFrame({"a":[1, None, 3]})
d.isna()

D) Notebook “magic commands” (36–44)

36) Run a shell command

!ls -la

37) Current directory (shell)

!pwd

38) Download a file (example)

# Example only: works if your environment has internet access
# !curl -L -o sample.txt https://example.com/file.txt

39) Auto-reload code you edit in .py files

%load_ext autoreload
%autoreload 2

40) Save a cell into a Python file

%%writefile my_utils.py
def add(a,b):
    return a+b

41) Import from your saved file

import my_utils
my_utils.add(2, 5)

42) Debug in notebook (simple)

def f(x):
    return 10 / x

# f(0)  # uncomment to see error

43) Launch debugger (Python 3.7+)

import pdb
# pdb.set_trace()  # set breakpoint and run cell

44) Capture output of a cell

%%capture cap
print("hello")
print("captured")
cap.stdout

E) Visualization + rich outputs (45–50)

45) Show an image (local file)

from IPython.display import Image
# Image("path/to/image.png")

46) Display multiple outputs cleanly

from IPython.display import display
display(df.head())
display(df.describe())

47) Progress bar

%pip install tqdm
from tqdm import tqdm
for _ in tqdm(range(20000)):
    pass

48) Interactive widgets (sliders/buttons)

%pip install ipywidgets
import ipywidgets as widgets
widgets.IntSlider(value=5, min=0, max=10)

49) Simple interactive function

import ipywidgets as widgets
from IPython.display import display

def show_square(x):
    print("square =", x*x)

slider = widgets.IntSlider(value=3, min=0, max=20)
widgets.interactive(show_square, x=slider)

50) Export notebook tips

  • From UI: File → Save and Export Notebook As → HTML / PDF
  • Keep notebooks clean by: Restart Kernel & Run All before sharing.

🔥 15 “Pro Tips” that make you fast in Jupyter

  1. Create a top cell called “Setup” (imports, config, paths).
  2. Use Markdown headings to structure like a mini-book.
  3. Name notebooks: 2026-02-14-topic-v1.ipynb for versioning.
  4. When you get weird errors: Kernel → Restart.
  5. Use %pip install ... inside notebook (avoids wrong pip).
  6. Always print sys.executable if packages behave oddly.
  7. Keep data in /data folder, code in /src folder.
  8. Use %%time before optimization—don’t guess.
  9. Keep cells small; one idea per cell.
  10. Avoid hidden state: run Restart & Run All regularly.
  11. Use display() for multiple outputs (better than print).
  12. Use autoreload when building utilities.
  13. Use tqdm for long loops so you know it’s not stuck.
  14. Don’t store secrets in notebooks; use env vars.
  15. Export to HTML for sharing—looks professional.

Leave a Reply