In this python pandas program, we will get the items of a series not present in another series using pandas library.
Steps to solve the program
- Import pandas library as pd.
- Create two series using pd.Series().
- Get the items of a series not present in another series using df1[~df1.isin(df2)].
- Print the output.
import pandas as pd
df1 = pd.Series([4,7,3,10])
df2 = pd.Series([9,4,3])
print("First series: \n",df1)
print("Second series: \n",df2)
result = df1[~df1.isin(df2)]
print(result)
Output :
First series:
0 4
1 7
2 3
3 10
dtype: int64
Second series:
0 9
1 4
2 3
dtype: int64
1 7
3 10
dtype: int64