I have below dataframes
import pandas as pd
dat1 = pd.DataFrame({'col1' : ['AA', 'AA'], 'col2' : [10,20]})
dat2 = pd.DataFrame({'col1' : ['AA', 'BB', 'AA', 'BB'], 'col2' : [11,11,11,11]})
Now I want to left-join above 2 based on col1
and col2
where dat1.col2 < dat2.col2
I tried below
dat_com = pd.merge(dat1, dat2, how = 'left', on = 'col1')
dat_com[dat_com['col2_x'] < dat_com['col2_y']]
But I think this is wrong approach as it eliminates the second row of dat1
, which I think should be in the final dat_com
as I am left-joining.
Could you please help to correct above method?