combine_first() 用法

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)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 在python中,众所周知,数据预处理最好用的包就是pandas了,以下是pandas里的dataframe数据结...
    天涯海角醉云游阅读 31,376评论 1 12
  • 写了个程序,对Pandas的绝大部分函数及其说明进行了中文翻译。原网址:http://pandas.pydata....
    TSIANG阅读 5,543评论 0 4
  • pandas入门 简介 pandas包含的数据结构和操作工具能快速简单地清洗和分析数据。 pandas经常与Num...
    python测试开发阅读 2,409评论 1 16
  • 表情是什么,我认为表情就是表现出来的情绪。表情可以传达很多信息。高兴了当然就笑了,难过就哭了。两者是相互影响密不可...
    Persistenc_6aea阅读 125,931评论 2 7
  • 16宿命:用概率思维提高你的胜算 以前的我是风险厌恶者,不喜欢去冒险,但是人生放弃了冒险,也就放弃了无数的可能。 ...
    yichen大刀阅读 6,098评论 0 4