1

I have a dataframe, df1, which certain columns having null values. To get the null values, I created another dataframe, df2, and in df2 I made those values non-null. I'll give an example of my dataframes here, bear in mind this is just an example as the actual dataframes are too long and this is simplified.

df1
   Col1 Col2 Col3
0    A    B    C    
1    D    E    F    
2  NaN    G  NaN     
3  NaN    H  NaN

df2
       Col1 Col3
    0    A    C    
    1    D    F    
    2    I    J     
    3    K    L

Now to replace a single column in df1, I can just use the following code

df1[Col1] = df2[Col1]

But how can I replace multiple columns like this at once? Is there a way I could replace Col1 and Col3 at the same time?

I tried some solutions from similar questions but they didn't work with mine.

1
  • df1.combine_first(df2)? Commented Jun 1, 2020 at 4:18

1 Answer 1

2

What I will do is update

df1.update(df2)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.