Skip to Content
Numerical Computing with Python
book

Numerical Computing with Python

by Pratap Dangeti, Allen Yu, Claire Chung, Aldrin Yim
December 2018
Beginner to intermediate
682 pages
18h 1m
English
Packt Publishing
Content preview from Numerical Computing with Python

There's more...

An exception to the preceding example takes place when the indexes contain the same exact elements in the same order. When this occurs, a Cartesian product does not take place, and the indexes instead align by their position. Notice here that each element aligned exactly by position and that the data type remained an integer:

>>> s1 = pd.Series(index=list('aaabb'), data=np.arange(5))>>> s2 = pd.Series(index=list('aaabb'), data=np.arange(5))>>> s1 + s2a    0
a    2
a    4
b    6
b    8
dtype: int64

If the elements of the index are identical, but the order is different between the Series, a Cartesian product occurs. Let's change the order of the index in s2 and rerun the same operation:

>>> s1 = pd.Series(index=list('aaabb'), data=np.arange(5)) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Numerical Computing with NumPy

Mastering Numerical Computing with NumPy

Umit Mert Cakmak, Tiago Antao, Mert Cuhadaroglu

Publisher Resources

ISBN: 9781789953633OtherOtherErrata Page