Skip to main content

Pandas DataFrame Intersection Operation

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
Tags
Submitted by devanshi.srivastava on February 15, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.