I have a pandas dataframe with 2 numeric columns such as:
col1 | col2 |
---|---|
2.5 | 4.1 |
5.1 | 2.2 |
3.0 | 7.8 |
And I also have a 2D dataframe such as:
0 | 3 | 5 | 10 |
---|---|---|---|
0 | A | D | E |
5 | B | F | G |
10 | C | H | I |
I need to find value in second table for each row in first table based on value in col1 is between indices in first column of second table and value in col2 fits between values in columns of second table.
I know it may sounds complicated, but I have this logic implemented in MS Excel and I need to transform it into Python. What is the best method to approach this problem.
One way could be to construct if statements, but the second table is quite large and may change in the future, so this is not an option for me. What could be solution to this? I thought about transforming second table into 1D with double indices.
Edit: Desired output is to have new column based on second table:
col1 | col2 | col3 |
---|---|---|
2.5 | 4.1 | A |
5.1 | 2.2 | B |
3.0 | 7.8 | D |
The logic is to lookup value with following conditions. We search for a row that the number in col1 is lower then value in a given index and larger than number in previous index at the same time. Same logic applies for columns dimension.