Issue
Suppose I have two dataframes:
df1
A B
-------
foo 2
bar 3
baz 4
and
df2
A B
-------
foo 40
bar 50
And I want the final result to be
A B
-------
foo 40
bar 50
baz 4
I can't figure out how to coax pd.update
, or pd.merge
into doing this.
Solution
Use, DataFrame.combine_first
:
df3 = df2.combine_first(df1)
df3
A B
0 foo 40.0
1 bar 50.0
2 baz 4.0
Answered By - Shubham Sharma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.