【发布时间】:2017-03-01 21:04:55
【问题描述】:
我有一个 DataFrame df,我想从那里减去 df2。
需要注意的是,我希望 df 保持相同的大小,并且对于 df 中的每个元素,我想减去 df2(如果 df2 中没有这样的唯一索引/列),那就是 df(i,j) - 0 (因为在 df2 中没有找到这样的索引/列)。
例子:
df:
Date Blue Dog Apple
1/1/2016 3 4 2
1/1/2015 3 4 2
1/1/2014 3 4 2
1/1/2013 3 4 2
1/1/2013 3 4 2
1/1/2013 3 4 2
df2:
Date Apple Blue Cat
1/1/2017 1 3 2
1/1/2016 1 3 2
1/1/2015 1 3 2
1/1/2014 1 3 2
我希望 df - df2 看起来像这样:
Date Blue Dog Apple
1/1/2016 0 4 1
1/1/2015 0 4 1
1/1/2014 0 4 1
1/1/2013 3 4 2
1/1/2012 3 4 2
1/1/2011 3 4 2
谢谢。
【问题讨论】:
标签: python pandas dataframe subtraction