Pandas Array (Pandas Series)-(3) Vectorization operations

Source: Internet
Author: User

This article describes how the pandas series with the index index is vectorized:

1. Index indexed arrays are the same:

S1 = PD. Series ([1, 2, 3, 4], index=['a','b','C','D']) S2= PD. Series ([ten, +, +], index=['a','b','C','D'])PrintS1 +s2a11b22C33D44Dtype:int64

Add the values corresponding to each index directly

2. Index indexed array values are the same, in different order:

S1 = PD. Series ([1, 2, 3, 4], index=['a','b','C','D']) S2= PD. Series ([ten, +, +], index=['b','D','a','C'])PrintS1 +s2a31b12C43D24Dtype:int64

Add the values corresponding to each index, whichever is the first series

3. Index indexed array Some values are the same, some values are different:

S1 = PD. Series ([1, 2, 3, 4], index=['a','b','C','D']) S2= PD. Series ([ten, +, +], index=['C','D','e','F'])PrintS1 +s2a nanb NaNc13.0D24.0e nanf NaN

The values corresponding to the same index values are added differently because they are not found, so the Nan is returned

4. Index indexed arrays are completely different:

S1 = PD. Series ([1, 2, 3, 4], index=['a','b','C','D']) S2= PD. Series ([ten, +, +], index=['e','F','g','h'])PrintS1 +s2a nanb NaNc NaNd NaNe nanf NaNg Nanh Nandtype:float64

Because there is no same index, the series cannot be added, and the result is Nan

Pandas Array (Pandas Series)-(3) Vectorization operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.