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