I want to check is a substring from DF1 is in DF2. If it is I want to return a value of a corresponding row.
DF1
| Name | ID | Region |
|---|---|---|
| John | AAA | A |
| John | AAA | B |
| Pat | CCC | C |
| Sandra | CCC | D |
| Paul | DD | E |
| Sandra | R9D | F |
| Mia | dfg4 | G |
| Kim | asfdh5 | H |
| Louise | 45gh | I |
DF2
| Name | ID | Company |
|---|---|---|
| John | AAAxx1 | Microsoft |
| John | AAAxxREG1 | Microsoft |
| Michael | BBBER4 | Microsoft |
| Pat | CCCERG | Dell |
| Pat | CCCERGG | Dell |
| Paul | DFHDHF |
Desired Output
Where ID from DF1 is in the ID column of DF2 I want to create a new column in DF1 that matches the company
| Name | ID | Region | Company |
|---|---|---|---|
| John | AAA | A | Microsoft |
| John | AAA | B | Microsoft |
| Pat | CCC | C | Dell |
| Sandra | CCC | D | |
| Paul | DD | E | |
| Sandra | R9D | F | |
| Mia | dfg4 | G | |
| Kim | asfdh5 | H | |
| Louise | 45gh | I |
I have the below code that determines if the ID from DF1 is in DF2 however I'm not sure how I can bring in the company name.
DF1['Get company'] = np.in1d(DF1['ID'], DF2['ID'])