I am trying to remove certain rows from a Pandas table. It is essentially a deduplication exercise:
I have a table
id sub_id1 sub_id2 date
0 1 424755 101 2018-09-21
1 2 424755 101 2018-09-21
2 3 424755 102 2018-09-21
3 4 678321 101 2018-09-21
4 5 678321 102 2018-09-22
5 6 424755 102 2018-09-22
I want to remove a row if there is another row that matches the sub_id1 and date, but has a lower sub_id2.
The SQL I would write for this would be
select * from table t
where not exists (select 1 from table
where sub_id1=t.sub_id1
and date=t.date
and sub_id2<t.sub_id2)
Resulting table would be
id sub_id1 sub_id2 date
0 1 424755 101 2018-09-21
1 2 424755 101 2018-09-21
2 4 678321 101 2018-09-21
3 5 678321 102 2018-09-22
4 6 424755 102 2018-09-22
Where id=3 is removed because there are rows that have the exact same sub_id1 and date column as it does, with a lower sub_id2.
Trying to figure this out using Pandas merges. Thanks!