在 pandas 中加入或合并覆盖 [英] join or merge with overwrite in pandas

查看:49
本文介绍了在 pandas 中加入或合并覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对具有日期时间索引的数据帧执行联接/合并/追加操作.

I want to perform a join/merge/append operation on a dataframe with datetime index.

假设我有df1,并且我想在其中添加df2. df2可以具有更少或更多的列以及重叠的索引.对于索引匹配的所有行,如果df2df1具有相同的列,我希望df1的值被df2的值覆盖.

Let's say I have df1 and I want to add df2 to it. df2 can have fewer or more columns, and overlapping indexes. For all rows where the indexes match, if df2 has the same column as df1, I want the values of df1 be overwritten with those from df2.

如何获得所需的结果?

How can I obtain the desired result?

推荐答案

如何:请注意,对于与df2不重叠的索引,它采用df1中的值.如果这不能完全满足您的要求,我将愿意改进此功能/为其添加选项.

Note that it takes the values from df1 for indices that do not overlap with df2. If this doesn't do exactly what you want I would be willing to improve this function / add options to it.

这篇关于在 pandas 中加入或合并覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆