np.isnan可以应用于本机dtype的NumPy数组(例如np.float64):
In [99]: np.isnan(np.array([np.nan, 0], dtype=np.float64))Out[99]: array([ True, False], dtype=bool)
但是在应用于对象数组时引发TypeError:
In [96]: np.isnan(np.array([np.nan, 0], dtype=object))TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
由于您拥有Pandas,
pd.isnull因此可以改用-它可以接受对象或本机dtypes的NumPy数组:
In [97]: pd.isnull(np.array([np.nan, 0], dtype=float))Out[97]: array([ True, False], dtype=bool)In [98]: pd.isnull(np.array([np.nan, 0], dtype=object))Out[98]: array([ True, False], dtype=bool)
请注意,
None在对象数组中也将其视为空值。



