Left Join In Pandas Without The Creation Of Left And Right Variables
I'm missing something in the syntax of merging in pandas. I have the following 2 data frames: >>> dfA s_name geo zip date value 0 A002X zip 60601 2010 None 1
Solution 1:
I think you need combine_first
with MultiIndex
created by set_index
:
cols = ["s_name","geo","zip","date"]
df = dfA.set_index(cols).combine_first(dfB.set_index(cols)).reset_index()
print (df)
s_name geo zip date value
0 A002X zip6060120101.01 A002Y zip6060120102.02 A003X zip606012010 NaN
3 A003Y zip6060120104.0
Or update
:
df = dfA.set_index(cols)
df.update(dfB.set_index(cols))
df = df.reset_index()
Post a Comment for "Left Join In Pandas Without The Creation Of Left And Right Variables"