Comparing Pd.series And Getting, What Appears To Be, Unusual Results When The Series Contains None
I am wondering why comparing two identical series with None value returns False: pd.Series(['x', 'y', None]) == pd.Series(['x', 'y', None]) 0 True 1 True 2 False dtype:
Solution 1:
This is by design:
see the warnings box: http://pandas.pydata.org/pandas-docs/stable/missing_data.html
This was done quite a while ago to make the behavior of nulls consistent, in that they don't compare equal. This puts
None
andnp.nan
on an equal (though not-consistent with python, BUT consistent with numpy) footing.So this is not a bug, rather a consequence of stradling 2 conventions.
I suppose the documentation could be slightly enhanced.
For equality of series containing null values, use pd.Series.equals
:
pd.Series(['x', 'y', None]).equals(pd.Series(['x', 'y', None])) # True
Post a Comment for "Comparing Pd.series And Getting, What Appears To Be, Unusual Results When The Series Contains None"