I have the two tables below: One table is Orders and the other table is a Master table. Both are dataframes in Pandas, Python.
Orders
-------------
Date | item_id
--------------
672022| 123
672022| 976
672022| 532
--------------
Master Table
----------------------------------------------
item_id | Description | Supplier | Ship_From
----------------------------------------------
234 | Oranges | CWF | NY
341 | Nuts | DVR | NJ
532 | Grapes | ETT | CT
123 | Apples | ERH | CT
976 | Raspberry | HKQ | NY
731 | Bread | FBE | NJ
-----------------------------------------------
I want my final table to look like the below:
-------------------------------
Date | item_id | Description
-------------------------------
672022| 123 | Apples
672022| 976 | Raspberry
672022| 532 | Grapes
-------------------------------
I am unable to get the desired output in a simple way What is the best way to write joins code in Python? I am using the below code:
new = pd.merge(orders, master, on="item_id", how="left")
new = new[['Date', 'item_id', 'description']]
new.drop_duplicates(subset=None, keep='first', inplace=True)