I have two data frames. They are structured like this:
df a
| Letter | ID |
|---|---|
| A | 3 |
| B | 4 |
df b
| Letter | ID | Value |
|---|---|---|
| A | 3 | 100 |
| B | 4 | 300 |
| B | 4 | 100 |
| B | 4 | 150 |
| A | 3 | 200 |
| A | 3 | 400 |
I need to take for each combo of Letter and ID in df A values from df B and run an outlier function on then.
Currently I am using over 40,000 rows of A and a list of 4,500,000 of list b
a['Results'] = a.apply(lambda x: outliers(b[(b['Letter']==x['Letter']) & (b['ID']==x['ID'])]['value'].to_list()),axis=1)
As you can imagine this is taking forever. Is there some mistake im making or something that can improve this code?