Python Learning Relationship test for the 16th day collection

Source: Internet
Author: User

When doing data analysis, to a set of analysis, and analysis of the relationship between multiple sets of analysis, then with the traditional cycle of comparison trouble, the collection provides a lot of methods, it is easy to compare the relationship of multiple sets, and set, intersection, difference set, symmetric difference set.

n1={1,2,4,6}

n2={2,3,5,6}

1. Usage of the intersection

N3=n1.intersection (N2)

n3={2,6}

or N3=N1&N2.

2, usage of the difference set

The difference of N1

N1.difference (N2)

N2.difference (N1)

or N1-N2, n2-n1.

3, the usage of the set

N1.union (N2)

or N1 | N2

4, Symmetrical difference set

Find the opposite value of the intersection

N1.symmetric_difference (N2)  

Happy learning, a little progress every day article from (JIU le network http://www.96net.com.cn/)

Python Learning Relationship test for the 16th day collection

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.