user5161995
user5161995

Reputation:

Find and remove rows in 1 data frame that do not exist in another using python pandas

I have 2 csv files of different length. I need to find and remove the rows in one file that do not exist in the other file. Is there an easy way to do this, other than looping through the 2nd file n times?

Upvotes: 0

Views: 41

Answers (1)

BENY
BENY

Reputation: 323226

Assuming you load your csv file into df1, and df2

df1[df1.apply(tuple,1).isin(df2.apply(tuple,1))]

Upvotes: 1

Related Questions