I have two DataFrames that look like this:
df1 (pretty small):
| index | sales |
|---|---|
| 1 | 10 |
| 2 | 20 |
and df2 (very large >5Mil):
| idx1 | idx2 |
|---|---|
| 1 | 2 |
and I want the final to look like this:
| idx1 | idx2 | totalSales |
|---|---|---|
| 1 | 2 | 30 |
I currently have this working but it is very slow:
df2['totalSales'] = df2.apply(lambda x: df1.loc[x]['sales'].sum(), axis=1)
Are there any faster/better ways to go about this? This works for me just fine, but it takes a very long time to run. Thanks in advance!