I have two dataframes df1 and df2.
df1 = pd.DataFrame({'type_id' : [1,2,3,4,3], 'count' : [12,11,15,16,2], 'unique_id' : ['1|12','2|11','3|15','4|16','3|2']})
df2 = pd.DataFrame({'type_id' : [1,3,76,12,11,1], 'count' : [8,6,15,16,5,17], 'col3' : [1,5,7,3,4,7], 'unique_id' : ['1|8','3|6','76|12','12|16','11|5','1|17']})
df1
type_id count unique_id
0 1 12 1|12
1 2 11 2|11
2 3 15 3|15
3 4 16 4|16
4 3 2 3|2
df2
type_id count col3 unique_id
0 1 8 1 1|8
1 3 6 5 3|6
2 76 15 7 76|12
3 12 16 3 12|16
4 11 5 4 11|5
5 1 17 7 1|17
Here, unique_id is a combination of type_id and count.
Now, I want to retrieve rows from df2 where df2['type_id'] == df1['id'] & df2['count']<df1['count']
i.e., I want rows where the two ids match and the corresponding count in df2 is less than the count of df1
Expected output:
type_id count col3 unique_id
0 1 8 1 1|8
1 3 6 5 3|6
when I try doing this directly I'm getting an error :
Can only compare identically-labeled Series objects
How do I perform this operation? Thanks in advance.