Another fairly common situation is to have two like-indexed (or similarly indexed) Series
or DataFrame
objects and wanting to “patch” values in one object from values for matching indices in the other. Here is an example:
In [133]: result = df1.combine_first(df2)
可见,combine_first() 方法能够实现数两张表的填充,实际使用中非常方便。
Note that this method only takes values from the right DataFrame
if they are missing in the left DataFrame
. A related method, update()
, alters non-NA values in place:
In [134]: df1.update(df2)