Broadcasting lets pandas apply an operation between a Series and a scalar by applying the scalar to every value and returning a new Series. Vectorized operations between two Series instead align values by index, not by position. section 1.7
Use broadcasting to:
- Add, subtract, compare, or otherwise operate on every Series value with one scalar, while preserving the Series index. section 1.7
- Combine two Series according to matching index labels, even when their labels appear in different orders. section 1.7
- Create boolean Series with comparisons, then use them as mask indexes for selection or assignment. section 1.13
- Assign one scalar to every selected DataFrame element, or provide a value collection with a matching shape. section 2.8
Shift test scores toward a target
Given a Series s of monthly scores, s + 10 adds ten points to every score. To make the mean equal to 80, calculate 80 - s.mean() and evaluate s + (80 - s.mean()). The mean produces a scalar, which broadcasting adds to each indexed score; the resulting values are floats. section 1.7
s = Series([10, 20, 30, 40],
index=list('abcd'))
s + 3
A minimal Series-plus-scalar example shows the operand, broadcast value, preserved labels, and resulting values together. section 1.7
Broadcast comparisons support expressions such as s.loc[s < 30] and s.loc[s <= s.mean()]. The comparison broadcasts across s, and the resulting boolean Series selects matching elements; the same mask can assign 999 to them. section 1.13


