Pandas 在执行二元运算(如加法和减法)之前,会自动对 Series 对象的数据索引进行对齐,但在检查相等性时不会这样做。为什么会这样,我该如何解决呢?
请看下面的示例:
请看下面的示例:
In [15]: x = pd.Series(index=["A", "B", "C"], data=[1,2,3])
In [16]: y = pd.Series(index=["C", "B", "A"], data=[3,2,1])
In [17]: x
Out[17]:
A 1
B 2
C 3
dtype: int64
In [18]: y
Out[18]:
C 3
B 2
A 1
dtype: int64
In [19]: x==y
Out[19]:
A False
B True
C False
dtype: bool
In [20]: x-y
Out[20]:
A 0
B 0
C 0
dtype: int64
我正在使用 pandas 0.12.0 版本。
0.13.1
中也会发生,问题很有趣。 - EdChum