Consider the following 'SeriesA' and 'SeriesB':
SeriesA
Index a 2 b 4 c 0 d 8 e 0 f 10
SeriesB
Index a 10 b -20 c -5 d 10 e 100 f 50
What will be the output of SeriesA * SeriesB?
Consider the following 'SeriesA' and 'SeriesB':
SeriesA
| Index | |
|---|---|
| a | 2 |
| b | 4 |
| c | 0 |
| d | 8 |
| e | 0 |
| f | 10 |
SeriesB
| Index | |
|---|---|
| a | 10 |
| b | -20 |
| c | -5 |
| d | 10 |
| e | 100 |
| f | 50 |
What will be the output of SeriesA * SeriesB?
Solution
✅ Correct Option: 3
Multiplying two pandas Series works element by element, matched on the index labels. Both series have the same index (a to f), so no NaN appears from mismatched labels.
| Index | SeriesA | SeriesB | Product |
|---|---|---|---|
| a | 2 | 10 | 20 |
| b | 4 | -20 | -80 |
| c | 0 | -5 | 0 |
| d | 8 | 10 | 80 |
| e | 0 | 100 | 0 |
| f | 10 | 50 | 500 |
Note that , which is not -0 or NaN, so the output is the same as Option 3.
Options 1, 2 and 4: NaN appears only when an index label is missing from one series, or when a value is itself NaN. A zero value gives 0, not NaN.
Related questions:
2025: 22 May Shift 1
2025: 27 May Shift 2
2025: 14 May Shift 1