O'Reilly logo

Learning pandas by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Arithmetic operations

Arithmetic operations (+, -, /, *, and so on) can be applied either to a Series or between two Series objects. When applied to a single Series, the operation is applied to all of the values in that Series. The following code demonstrates arithmetic operations applied to a Series object by multiplying the values in s3 by 2. The result is a new Series with the new values (s3 is unchanged).

In [46]:
   # multiply all values in s3 by 2
   s3 * 2

Out[46]:
   a    2
   b    4
   c    6
   dtype: int64

The preceding code is also roughly equivalent to the following code, which creates a new series from a scalar value using the index from s3. It has the same result, but it is not as efficient, as alignment is performed between the Series objects instead ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required