-1

I have two dataframes.

enter image description here

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?

loksan
  • 157
  • 3
  • 17

1 Answers1

1

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)
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252