I'm iterating over multiple pandas data frames where on each iteration I extract 2 lists. Then, for each 2 lists combination, I need to find the row in another Data Frame where each combination of all values in the 2 lists appears.
Simplified example:
The df looks like this (any D_val P_val may appear only once):
D_val | P_val | D_PCode
A | 1 | 25
D | 1 | 21
C | 2 | 32
B | 4 | 35
D | 2 | 126
B | 1 | 3
C | 1 | 312
For a single iteration with the following lists -
list1 = [1,2]
list2 = [A,B,C]
I expect to get the following list:
[25, 3, 312, 32]
Explanation:
for [A,1] - 25
for [A,2] - nothing
For [B,1] - 3
etc.
I implemented it using nested loops, but with multiple iterations, large data frame and long lists it takes far too long.
Any suggestions how to efficiently implement it? I'm happy to use other data structures if needed.