最起码,我希望在比较中,NaN数值小于任何其他数值。
假设我有s1和s2,
s1 = pd.Series([1, 3, np.nan, 5, np.nan, -1, np.nan])
s2 = pd.Series([2, 1, np.nan, np.nan, 2, np.nan, -1])
当我将它们比较为s1 <s2时,我需要以下行为:
Out:
0 True
1 False
2 False
3 False
4 True
5 False
6 True
简单地使用Series.fillna
函数和np.NINF
常量:
In [256]: s2.fillna(np.NINF) > s1.fillna(np.NINF)
Out[256]:
0 True
1 False
2 False
3 False
4 True
5 False
6 True
dtype: bool
np.NINF
-NumPy常数,负无穷大的浮点表示本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句