Concept 1 of 71 min
NumPy: views, axes, broadcasting and masks
A slice is a view
| a | np.arange(6) |
|---|---|
| b | a[2:4] |
- a is [0 1 2 3 4 5]
- b views the 2 and the 3
- b[0] = 50 makes a [0 1 50 3 4 5]
Setting b changed a too, while a[2:4].copy() would have left a as it was.
The axis that disappears
| Array | [[2, 4], [6, 8]] |
|---|---|
| axis | 0 |
- First column: (2 + 6) ÷ 2 = 4
- Second column: (4 + 8) ÷ 2 = 6
axis=0 averages down each column, giving 4 and 6.
An array times 2 doubles each element where a list times 2 repeats it. Setting axis=0 collapses the rows to one value per column, broadcasting stretches (3,) and (2, 1) into (2, 3), and a boolean mask filters without a loop.
Views make NumPy fast on large data but surprise anyone used to lists. Mixing lists and arrays silently changes lengths: the list [1, 2] multiplied by 2 has 4 items.
Read axis as 'the axis that disappears': axis=0 averages down each column, axis=1 across each row.
Broadcasting is powerful and a common source of silent shape bugs, so check .shape when results look odd. x[x > 2] keeps the matching items, replacing explicit loops with compiled filters.
- Expecting a NumPy slice to be independent.
- Mixing up axis=0 and axis=1.
- Multiplying a list and expecting element-wise results.
A colleague's function modifies a NumPy array it was given and the caller's data changes too. Why, and how do you make it safe?
A complete answer covers
- Arrays are passed by reference and slices are views.
- In-place operations change the caller's memory.
- Copy at the boundary with .copy() when the function must modify.
- Or write the function to return a new array.
Also in our technical interviews, on camera, with a score.
Concept 2 of 71 min
NaN: missing values that spread
The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.
See the plansSign inConcept 3 of 71 min
pandas indexing and assignment
The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.
See the plansSign inConcept 4 of 71 min
Merges, counts and speed
The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.
See the plansSign inConcept 5 of 71 min
Time series in pandas: returns, windows and dates
The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.
See the plansSign inConcept 6 of 71 min
Python traps that come up with data
The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.
See the plansSign inConcept 7 of 71 min
AdvancedWhy NumPy is fast: memory layout
The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.
See the plansSign inRecap
- A NumPy slice is a view, a list slice a copy; * repeats a list but multiplies an array element by element.
- NaN is a float, never equal to itself; pandas skips it in sums and means, NumPy does not.
- Index and assign in one .loc call; combine conditions with &, | and ~, each in brackets.
- A left join adds rows when the right key repeats; overlapping columns get _x and _y.
- Shift signals by 1 day before multiplying by returns, compound with (1 + r).cumprod(), and say dayfirst=True for European dates.
25 questions on Python for data
Timed, like the real one, drawn from a bank of 33. Every answer explained.