这个怎么样.首先检查NaN是否在同一个地方(使用
isnull):
In [11]: s1.isnull()
Out[11]:
0 False
1 True
dtype: bool
In [12]: s1.isnull() == s2.isnull()
Out[12]:
0 True
1 True
dtype: bool
然后检查非NaN的值是否相等(使用notnull):
In [13]: s1[s1.notnull()]
Out[13]:
0 1
dtype: float64
In [14]: s1[s1.notnull()] == s2[s2.notnull()]
Out[14]:
0 True
dtype: bool
为了平等,我们需要两者都是真的:
In [15]: (s1.isnull() == s2.isnull()).all() and (s1[s1.notnull()] == s2[s2.notnull()]).all()
Out[15]: True
如果这还不够,你也可以检查姓名等.
如果你想在不同的情况下加注,请使用pandas.util.testing中的assert_series_equal:
In [21]: from pandas.util.testing import assert_series_equal
In [22]: assert_series_equal(s1, s2)