How to filter dataframe from a set of tuples, so that the pairing is the same? I need a more elegant way of writing. Im trying not to use merge because it will make it less efficient.
So I have a list of tuple called tup_list:
[('118', '35'), ('35', '35'), ('118', '202')
Assuming the first element in each tuple is A, and the second is B, I am trying to filter my dataframe according to this tup_list, where the pairing needs to be the same.
Original dataframe:
A B
118 35
118 40
35 202
118 1
35 35
After filtering according to the tup_list, the new dataframe should be:
A B
118 35
35 35
Only exact pairings should be returned.
Currently Im using df= df.merge(tup_list, on=['A','B'], how='inner'). But is not very efficient as my actual data is larger.
Please advise on more efficient way of writing.