I have a dataframe (df1) like this:
| Index | Name | Val1 |
|---|---|---|
| 1 | Dan | 50 |
| 3 | Adam | 75 |
| 4 | Larry | 35 |
| 7 | Lou | 75 |
And another one (df2) like this:
| Index | Name | Val2 |
|---|---|---|
| 1 | Peter | 5 |
| 2 | Dan | 10 |
| 5 | Mitch | 20 |
| 7 | Lou | 25 |
I want to create a new dataframe (df3) resulting like this:
| Index | Name | Val1 | Val 2 |
|---|---|---|---|
| 0 | Dan | 50 | 10 |
| 1 | Adam | 75 | |
| 2 | Larry | 35 | |
| 3 | Lou | 75 | 25 |
| 4 | Peter | 5 | |
| 5 | Mitch | 20 |
Kind of appending the Val2 column from df2 to df1 but only the values corresponding to the right name, leaving empty where there is no Val 2 for that name, and adding the names (rows) that have Val2 but no Val1.
I'm not sure if I'm explaining myself, here.
I tried using groupby and other options but kept getting messed results.