1

I have two datasets:

First Dataset:

Customer_Key     Incentive_Amount
3434                32
5635                56
6565                NaN
3453                45

Second Dataset:

Customer_Key     Incentive_Amount
3425                87
6565                22
1474                46
9842                29

First Dataset has many rows where incentive_amount value is NaN. but it is present in second dataset. For example, See customer_Key = 6565, it's incentive_amount is missing in dataset_1 but present in dataset_2. So, For all NaN values of incentive_amount in dataset_1, copy the incentive_amount value from dataset_2 based on matching customer_key.

Psuedocode will be like:

df_1['incentive_amount'] = np.where(df_1['incentive_incentive']='NaN',
                                 (df_1['incentive_amount'].fillna(df_2['incentive_amount']) 
 if 
   df_1['customer_key'] = df_2['customer_key']),
                                         df_1['incentive_amount'])
Patrik
  • 75
  • 6
  • 2
    I think your question is similar to this one, this answer might help: https://stackoverflow.com/questions/41773728/pandas-fillna-with-data-from-another-dataframe-based-on-the-same-id – Kcode Jan 23 '22 at 21:49
  • @wwnde, Pandas Merging 101? This is not the main goal of this answer, isn't it? – Corralien Jan 23 '22 at 21:57
  • @corralien, it is a possible solution. We should encourage some reading. I provided more read options. You can open the question if you need to – wwnde Jan 23 '22 at 22:04

1 Answers1

0

There are many ways to do this. Please do some reading

combine_first

update

merge

wwnde
  • 26,119
  • 6
  • 18
  • 32