Reputation: 23
I have 2 dataframes outputted from my python script: dt1
& dt2
Each dataframe has 4 columns (colA
, colB
, colC
, & colD
) and each dataframe has a different length (dt1
always has more rows)
I want to create a 3rd dataframe dt3
that:
dt1
dt2[colD]
value to the corresponding row IF dt1[colA]
= dt2[colA]
& dt1[colB]
= dt2[colB]
& dt1[colC]
= dt2[colC]
, if the 3 columns don't match I want to load nullI've tried iterating through using a for loop with combined if else statements but can't seem to get the check piece right, please help!
Upvotes: 1
Views: 95
Reputation: 650
Use merge
from pandas
df1.merge(df2[["colA","colB","colC","colD"]],on=["colA","colB","colC"])
Updated as Op req.
df1.colD.fillna('---')
Upvotes: 1