我有两个 D ataFrame
,其中一个大于另一个(A)。B 上的标签都包含在 A 中。我想为对应的行/列值取差值 (AB)。有没有人有什么建议?
问问题
194 次
1 回答
1
You should be able to simply do A.sub(B). For example:
df = DataFrame(np.random.randn(4, 2), columns=['one','two'])
A = df.ix[1:, ['one', 'two']]
B = df.ix[:2, ['one']].apply(lambda x: x *2)
If A is:
one two
1 -0.999523 -2.111082
2 -2.197760 -0.412689
3 -0.534728 0.037255
and B is:
one
0 -1.940326
1 -1.999046
2 -4.395521
A.sub(B) will give you:
one two
0 NaN NaN
1 0.999523 NaN
2 2.197760 NaN
3 NaN NaN
Or have I misunderstood the question?
于 2012-07-31T14:12:16.943 回答