pandas.isnull()(也是
pd.isna(),在较新的版本中)检查数字数组和字符串/对象数组中的缺失值。从文档中,它检查:
数字数组中的NaN,对象数组中的None / NaN
快速示例:
import pandas as pdimport numpy as nps = pd.Series(['apple', np.nan, 'banana'])pd.isnull(s)Out[9]: 0 False1 True2 Falsedtype: bool
numpy.nan用来表示缺失值的想法是
pandas引入的,这就是为什么
pandas有工具来处理它的原因。
日期时间也是如此(如果使用
pd.NaT,则无需指定dtype)
In [24]: s = Series([Timestamp('20130101'),np.nan,Timestamp('20130102 9:30')],dtype='M8[ns]')In [25]: sOut[25]: 0 2013-01-01 00:00:001 NaT2 2013-01-02 09:30:00dtype: datetime64[ns]``In [26]: pd.isnull(s)Out[26]: 0 False1 True2 Falsedtype: bool


