Find if a dataframe is a subset of an another dataframe, while ignoring index
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Dream Voyager Looping
--
Chapters
00:00 Find If A Dataframe Is A Subset Of An Another Dataframe, While Ignoring Index
00:38 Accepted Answer Score 4
01:04 Thank you
--
Full question
https://stackoverflow.com/questions/5714...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pandas #dataframe
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Dream Voyager Looping
--
Chapters
00:00 Find If A Dataframe Is A Subset Of An Another Dataframe, While Ignoring Index
00:38 Accepted Answer Score 4
01:04 Thank you
--
Full question
https://stackoverflow.com/questions/5714...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pandas #dataframe
#avk47
ACCEPTED ANSWER
Score 4
Possible solution is use merge by all columns (no parameter on) and then use isin with subset:
print (ex2.merge(ex).isin(ex2))
col1 col2 col3
0 True True True
1 True True True
print (ex2.merge(ex).isin(ex2).all().all())
True
Another idea is compare MultiIndexes:
i1 = ex2.set_index(ex2.columns.tolist()).index
i2 = ex.set_index(ex.columns.tolist()).index
print (i1.isin(i2).all())
True