I have a dataframe like this:
id1 name id2 val
0 1 'A' 1 4
1 1 'B' 1 1
2 2 'C' 3 1
.
.
.
I have another dataframe that is as follows:
new_val
1 2
3 4
I want to make the first dataframe as follows:
id1 name id2 val
0 1 'A' 1 2.0
1 1 'B' 1 0.5
2 2 'C' 3 0.25
.
.
.
What I want to do is divide the val column in the first dataframe with the value that matches the index to column id2. We see that id2 = 1 then we divide val = 4 by 2 since it corresponds to index 1. id2 = 3 then we divide val=1 by 4 to get 0.25.
I know I could add these into lists of tuples and perform the computation and reset the column, but is this possible with pandas functions? Using for loops for really large datasets would be really computationally expensive.