0

I have two dataframes, df1 and df2 as follows:

#TWO DFs
df1 = {'uuids': [[01, 03], [02], [02,03]} 

df2 = {'uuid':[01, 02, 03]}

These are instances of originals. My question is how to efficiently (speedwise) print df2 if it finds a value 01 present in df1?

Currently, I am doing following-

for j in range(len(df1)):
    for i in df1['uuids'][j]:# GOES THROUGH EACH VALUE INSIDE LIST OF COLUMN uuids
        print (df2[df2['uuid'] == i])# PRINTS df2 IF THERE IS A MATCH

Thank you for your time and help!

Rishabh Sahrawat
  • 2,437
  • 1
  • 15
  • 32

1 Answers1

0

If using pandas>=0.25, you can use explode and compare the values:

df2['uuid'].isin(df1.explode('uuids')['uuids'].values)

Out[1]:
0    True
1    True
2    True
realr
  • 3,652
  • 6
  • 23
  • 34