1

I have two dataframes, one (A) contains the notes associated with certain accounts. The other (B) is a list of accounts that i wish to add a column containing the note for that account. In this example there will be times when the account number in dataframe B is not in dataframe A and i would like to fill this either NaN or 0.

Input:

Dataframe A:

Account  Note
11       a
12       b
13       c
14       d
15       e
16       f

Dataframe B:

Account  
11       
25       
42       
14       
15       
19 
26      

Desired Output:

Dataframe C:

Account  Note
11       a
25       
42       
14       d
15       e
19       
26

Note that in my real world example the size of Dataframe B will be much bigger than A

1 Answers1

1

Try merge with how='left' and on='Account':

>>> df_b.merge(df_a, how='left', on='Account')
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
U13-Forward
  • 69,221
  • 14
  • 89
  • 114