How do I join or concat 2 dataframes where I get a new column for each row where the left_on/right_on key is the same?
Given 2 dataframes: DF1
| ID | Name |
|---|---|
| 123 | Jim |
| 456 | Bob |
DF2
| ID | JobCode |
|---|---|
| 123 | H1B |
| 456 | H1B |
| 456 | H2B |
I want to merge/join/groupby, not sure really such that the result is:
| ID | Name | JobCode | JobCode_x |
|---|---|---|---|
| 123 | Jim | H1B | |
| 456 | Bob | H1B | H2B |
so kind of like a join, I need to be able to join data on a value but I want to add columns instead of adding rows, when there are multiple matches, and the number of matches cant be known upfront so it could need to add 10 columns.
I tried a horizontal concat but it doesnt seem to match on value I have also read up a bunch on groupby, but I can't get it.
any help would be appreciated.
from Recent Questions - Stack Overflow https://ift.tt/2NY6sdm
https://ift.tt/eA8V8J
Comments
Post a Comment