【发布时间】:2020-02-25 20:38:26
【问题描述】:
我有df1,其中包含:
IDs values
E21 32
DD12 82
K99 222
而df2 包含:
IDs values
GU1 87
K99 93
E21 48
我需要检查df2 中的ID 是否存在于df1 中,为df1 减去value - df2 以获取ID 并更新@987654332 @在df2.
如果df2 中的ID 不存在于df1 中,则df2 中该ID 的值保持不变。
所以,上面例子的结果(基本上df2会更新):
IDs values
GU1 87 #the same not changed since it not exist in df1
K99 129 #exist in df1, do the subtraction 222-93=129
E21 -16 #exist in df1, do the subtraction 32-48=129
有什么帮助吗?
【问题讨论】:
-
IDs中的df1是唯一的吗? -
是的,它们是独一无二的@QuangHoang
标签: python pandas subtraction