Comparing pandas Series for equality when they contain nan?
问题 My application needs to compare Series instances that sometimes contain nans. That causes ordinary comparison using == to fail, since nan != nan : import numpy as np from pandas import Series s1 = Series([1,np.nan]) s2 = Series([1,np.nan]) >>> (Series([1, nan]) == Series([1, nan])).all() False What's the proper way to compare such Series? 回答1: How about this. First check the NaNs are in the same place (using isnull): In [11]: s1.isnull() Out[11]: 0 False 1 True dtype: bool In [12]: s1.isnull(