Basically I have two Pandas dataframes A and B as follows. What would be the easiest / computationally fastest way to combine A and B to get C? I'm currently using a for
loop to iterate bag_name
in dfB
row-by-row but this could be slow for large dataframes.
I suspect there must be some built-in methods in Pandas to combine these dataframes - I apologise if this had been asked somewhere else - I don't know what keyword to search for.
DataFrame A (dfA)
| bag_name | ID | price |
|----------|------|-------|
| a | asdf | 1 |
| b | qwer | 2 |
| c | zxcv | 3 |
DataFrame B (dfB)
| bag_name | item_name | weight |
|----------|-----------|--------|
| a | t | 2.3 |
| b | y | 2.4 |
| b | u | 2.5 |
| c | i | 2.6 |
| c | o | 2.7 |
| c | p | 2.7 |
DataFrame C (dfC)
| bag_name | ID | Price | item_name | weight |
|----------|------|-------|-----------|--------|
| a | asdf | 1 | t | 2.3 |
| b | qwer | 2 | y | 2.4 |
| b | qwer | 2 | u | 2.5 |
| c | zxcv | 3 | i | 2.6 |
| c | zxcv | 3 | o | 2.7 |
| c | zxcv | 3 | p | 2.7 |