In Pandas DataFrame Set Operation we can use merge() method to perform intersection operation. merge() function is a pre-defined function that can be used to do an intersection between two sets. It keeps the values present in both dataframe. This function takes both the dataframe as an argument.
Example
import pandas as pd
A = pd.DataFrame ({"name":["Jack","Alice"],
"Roll_No":[13,15]})
print(A)#first dataframe
Output
name Roll_No
0 Jack 13
1 Alice 15
B = pd.DataFrame ({"name":["Jack","Monica"],
"Roll_No":[13,19]})
print(B)#second dataframe
Output:
name Roll_No
0 Jack 13
1 Monica 19
result=A.merge(B)
print(result)
Output:
name Roll_No
0 Jack 13