I have two dataframes.
For all rows in df1, find the corresponding row in df2 (through matching key) and update the final column in df2 to 1. How shall I proceed in pandas?
Remove column final
, use left join with indicator
parameter, so is possible create 1,0
column by mapping True, False
by compare both
:
df = df2.drop('final', axis=1).merge(df1, how='left', indicator='final')
df['final'] = df['final'].eq('both').astype(int)