eljusticiero67 eljusticiero67 - 1 month ago 13
Python Question

Check if multiple rows exist in another dataframe

I have a two dataframes. I want to see if a specific row (in its entirety) exists in the other dataframe. Example row from df_subset:

id category value date
1 A 10 01-01-15
3 C 10 03-01-15


The other df_full:

id category value date
1 A 10 01-01-15
2 B 10 02-01-15
3 C 10 03-01-15
4 D 16 04-01-15


Is there someway to check if the rows of one dataframe exists in another? Something like this (obviously this does not work):
df_subset in df_full
, exist?

> True

Answer

I think you can use merge with inner join (by default) with DataFrame.equals for compare with df_subset:

print (pd.merge(df_subset,df).equals(df_subset))
True