Loading Python, NumPy and pandas in your browser… (first time ~25 MB, then cached)
Lesson 01🔢NumPy essentialsFoundation
Arrays: one shape, one type
A NumPy array is one block of numbers with a single dtype and a shape that says how to read it.
You’ll use
np.array · .dtype · .shape · np.arange · reshapeWatch the data move
Meet the Copper Kettle café — its sales are the data for this part of the course. Watch a plain Python list become an array, pick up a `dtype` and a `shape`, grow into a 2-D table, and get re-read with `reshape`.
The mental modelAn array is **one block of memory + one dtype + a shape**. The shape is just instructions for reading the block: change it with `reshape` and the numbers stay exactly where they were.
Why it matterspandas is built on NumPy: every DataFrame column is an array underneath. One type per array is what makes whole-column maths fast — and it is why a single stray string or `NaN` quietly changes a column’s dtype.
🧪 Change `tea` to include a decimal such as `12.5` and replay — the dtype in the second frame becomes `float64`.
The moves, line by line
Tap a note to see its line.
⌘/Ctrl + Enter · bare expressions show their value
Output
Run to see each result- line 2The four facts to check first on any array: its type, its shape, how many axes, how many cells.
- line 5For 2-D arrays the shape is `(rows, columns)`.
- line 7`:` means “all of this axis” — here every row, column 1.
- line 9Like `range`: the stop is left out, so this is 0, 2, 4, 6, 8.
- line 13`reshape` never changes the values or their order, only how they are read.
- line 15`astype` makes a new array of another dtype; float → int drops the decimals.
Gotchas
- One string turns the whole array into strings: `np.array([1, 2, "3"])` gives `array(["1", "2", "3"])`, and `.sum()` then fails.
- `reshape` needs the same number of cells: `np.arange(10).reshape(3, 4)` raises a ValueError (10 ≠ 12).
- A shape of `(4,)` (one axis) is not the same as `(4, 1)` (four rows, one column) — it matters as soon as you combine arrays.
- The default integer size depends on the machine: `int64` on most computers, `int32` in this in-browser Python. Write `dtype="int64"` when it matters (very large totals).
Pro tips
- Use `-1` in `reshape` for “whatever fits”: `a.reshape(-1, 7)` turns any multiple of 7 days into weeks.
- Print `a.dtype` whenever a result looks odd — it explains most surprises.
Before you run it
Your turn, on real-looking data
Find the bug
Run it, spot the trap, repair it.
Answer everything, then submit
7 of 8 correct passes the lesson and unlocks the next one.