Skip to content
Justice Tech School

Series Arithmetic

Arithmetic on Series is vectorized and aligns on the index. Labels that do not match give NaN.

Example
import pandas as pd
import numpy as np
a = pd.Series([1, 2, 3], index=['x', 'y', 'z'])
b = pd.Series([10, 20, 30], index=['y', 'z', 'w'])
print(a * 2)
print(a + b)

Result

x    2
y    4
z    6
dtype: int64
w     NaN
x     NaN
y    12.0
z    23.0
dtype: float64

Exercise

Add 5 to every value.

s  5

Quiz Test

What happens to labels that do not match?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.