I have two Data Frames:
DataFrame 1
df1 = pd.DataFrame()
df1["ID1"] = [np.nan, 1, np.nan, 3]
df1["ID2"] =[np.nan, np.nan , 2, 3]
df1
DataFrame 2
df2 = pd.DataFrame()
df2["ID"] = [1, 2, 3, 4]
df2
And I need to merge these two DataFrames using below conditions:
- If in df1 ID1 == ID2 then I can merge df1 with df2 using
df1.ID1 = df2.IDordf1.ID2 = df2.ID - If in df1 ID1 != ID2 then I have to mergre df1 with df2 using both mentioned in point 1 conditions means:
df1.ID1 = df2.IDanddf1.ID2 = df2.ID
I have the command as above in points 1 and 2, nevertheless I totaly do not know how to write it in Python Pandas, any suggestions ?