I want to map one column of dataframe to another dataframe by using multiple columns. The sample dataframes are as follow:
df1 = pd.DataFrame()
df1['Date'] = ['2018-08-10','2018-08-10','2018-08-10','2018-08-10','2018-08-10',
'2018-08-11','2018-08-11','2018-08-11','2018-08-12','2018-08-12',
'2018-08-13','2018-08-12','2018-08-12','2018-08-12','2018-08-12']
df1['Name'] = ['A','A','A','A','A',
'B','B','B','C','C',
'D','D','E','F','F']
df1 ['Orgz'] = ['Alpha','Alpha','Alpha','Alpha','Alpha',
'Beta','Beta','Beta','Gamma','Gamma',
'Theta','Theta','Theta','Theta','Theta']
df2 = pd.DataFrame()
df2['Date'] = ['2018-08-10','2018-08-11','2018-08-12','2018-08-12','2018-08-13','2018-08-12','2018-08-12']
df2['Name'] = ['A','B','C','D','D','E','F']
df2 ['Orgz']= ['Alpha','Beta','Gamma','Theta','Theta','Theta','Theta']
df2 ['min'] = [60,85,90,77,25,20,30]
I want to map the column df2.min to df1 by creating a new column. However, I have three common columns which are Date, Name and Orgz to Map. In this case, I cannot just use Name to map it as there will be the same name at different date in my actual database. So I decided to use three columns (Date,Orgz and Name) to map with df2. The result will be assinged to a new column in df1. My actual result will look like as follow:
From the results, you will notice that some of the name are multiple at the same date. in that case, I just want to map the min value on the first row, the rest of the row are set to 0.
How can I do it?
Thanks, Zep
