Chapter 6 Operators (& Dunder Methods)
Contents
Chapter 6 Operators (& Dunder Methods)¶
Per usual we’ll import a few packages
import pandas as pd
import numpy as np
And generate a quick numerical series. One that starts at 0 (inclusive), increments by 2, and stops at 22 (non-inclusive).
s = pd.Series(np.arange(start = 0, stop = 22, step = 2))
Let’s display the values associated with s
s
0 0
1 2
2 4
3 6
4 8
5 10
6 12
7 14
8 16
9 18
10 20
dtype: int32
Exercise 1¶
Add a numeric series to itself
s + s
0 0
1 4
2 8
3 12
4 16
5 20
6 24
7 28
8 32
9 36
10 40
dtype: int32
Exercise 2¶
Add 10 to a numeric series
s + 10
0 10
1 12
2 14
3 16
4 18
5 20
6 22
7 24
8 26
9 28
10 30
dtype: int32
Exercise 3¶
Add a numeric series to itself using the
.add
method.
s.add(s)
0 0
1 4
2 8
3 12
4 16
5 20
6 24
7 28
8 32
9 36
10 40
dtype: int32