I have two data frames which have identical columns and the exact same number of rows
Data frame 1 has the original data and data frame 2 contains the fields which have changed (changed fields contain the new value, unchanged fields are nan).
I want to essentially overlay the "new data" in df 2 over the data in df 1 and get the result below.
df1:
Key a b
123 6 1
124 7 6
125 3 5
df2:
Key a b
123 nan nan
124 8 nan
125 nan 4
Result df:
Key a b
123 6 1
124 8 6
125 3 4
You need combine_first
:
df2.combine_first(df1)
Output:
Key a b
123 6.0 1.0
124 8.0 6.0
125 3.0 4.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With