I have 2 data frames df1 and df2
df1 = pd.DataFrame({'ID': [1, 2, 3, 5],
'Name': ['client', 'detail_client', 'operations', audit],
'Type': ['str', 'var', 'str', 'nvar']})
df2 = pd.DataFrame({'ID': [5, 3, 7, 2],
'Name': ['audit', 'operations', 'C', 'detail_client'],
'Type': ['nan', 'nan', 'nan', 'nan']})
I would like to create a function that takes as arguments df1, df2, df1['ID'], df2['ID'], df1['Name'], df2['Name'], df1['Type'] and df2['Type'] because columns label may not always identical.
For each row of df1. Iterate over df2. Compare df1['ID'] value with df2['ID'] and df1['Name'] value with df2['Name']. When true. Set df2['Type']=df1['Type']. The function should return df2 with df2['Type'] equal to df1['Type'] when the condition is true.
I expect df2 to be like the following df:
df2 = pd.DataFrame({'ID': [5, 3, 7, 2],
'Name': ['audit', 'operations', 'nan', 'detail_client'],
'Type': ['nvar', 'str', 'nan', 'var']})
Any help is welcomed. Thanks in advance.