1.

How will you get the items that are not common to both the given series A and B?

Answer»

We can achieve this by FIRST performing the union of both series, then taking the intersection of both series. Then we follow the approach of GETTING items of union that are not there in the list of the intersection.

The FOLLOWING code demonstrates this:

import pandas as pdimport numpy as npdf1 = pd.Series([2, 4, 5, 8, 10])df2 = pd.Series([8, 10, 13, 15, 17])p_union = pd.Series(np.union1d(df1, df2)) # union of seriesp_intersect = pd.Series(np.intersect1d(df1, df2)) # intersection of seriesunique_elements = p_union[~p_union.isin(p_intersect)]print(unique_elements)"""Output:0 21 42 55 136 157 17dtype: int64"""


Discussion

No Comment Found