...

/

Multiplying Values of Pandas Series

Multiplying Values of Pandas Series

Let's find out how a pandas series works with the all method and equality operator.

We'll cover the following...

Try it yourself

Try executing the code below to see the result.

Python 3.8
import pandas as pd
v = pd.Series([.1, 1., 1.1])
out = v * v
expected = pd.Series([.01, 1., 1.21])
if (out == expected).all():
print('Math rocks!')
else:
print('Please reinstall universe & reboot.')

Explanation

The out == expected command returns a Boolean pandas.Series. The all method returns True if all elements are True.

When we look at out and expected, they seem the same.

In [1]: out
Out[1]:
0 0.01
1 1.00
2 1.21
dtype: float64
In [2]: expected
Out[2]:
0 0.01
1 1.00
2 1.21
dtype: float64

But, when we compare ...