*I edited the question a little based on the answers I received!
This is my first data frame. In reality, it has over 30K columns = df
| cl_id | gained_from_sup | lost_to_sup | fixed_term |
|---|---|---|---|
| 1001 | 3 | 5 | NaN |
| 1002 | 1 | 1 | NaN |
| 1003 | 4 | 2 | 12 |
| 1004 | 1 | 3 | 6 |
This is my second dataframe which has the supplier ID - this matches the numbers in gained from Sup and lost to Sup to the corresponding supplier name = df_supp
| supplier_id | supplier_name |
|---|---|
| 1 | KFC |
| 2 | Costa |
| 3 | Nandos |
| 4 | Starbucks |
| 5 | Burger King |
After merging them using pd.merge and how’left’, left on gained from… right on supp Id..
It outputs the first df with df_supp to the end. It does match the keys correctly but is there a way to replace the iDS in df with the names from df2 since the table will not make sense when 2 Columns (gained_from and lost_from in df1 the supp_id when merged only matches the gained on.
This is my desired output:
| cl_id | gained_from_sup | lost_to_sup | fixed_term |
|---|---|---|---|
| 1001 | Nandos | Burger King. | NaN |
| 1002 | KFC | KFC. | NaN |
| 1003 | Starbucks | Costa. | 12 |
| 1004 | KFC | Nandos. | 6 |
Or is there a better way to reformat the table to show the corresponding IDs and names for both gained_from_sup and lost_from_sup?