0 votes
in Python Pandas by
How to get the items not common to both series A and series B?

1 Answer

0 votes
by
We get all the items of p1 and p2 not common to both using below example:

import pandas as pd

import numpy as np

p1 = pd.Series([2, 4, 6, 8, 10])

p2 = pd.Series([8, 10, 12, 14, 16])

p1[~p1.isin(p2)]

p_u = pd.Series(np.union1d(p1, p2))  # union

p_i = pd.Series(np.intersect1d(p1, p2))  # intersect

p_u[~p_u.isin(p_i)]

Output:

0     2

1     4

2     6

5    12

6    14

7    16

dtype: int64

Related questions

0 votes
asked Aug 14, 2021 in Python Pandas by SakshiSharma
0 votes
asked Aug 13, 2021 in Python Pandas by SakshiSharma
...