DataFrame.isna() - 检测数据帧中的无效值
DataFrame的isna()方法返回一个同样大小的布尔类型数据帧,表示原数据帧 中的对应值是否无效。
方法原型
DataFrame.isna(self)
返回值:
isna()方法返回一个大小相同的DataFrame对象,其布尔类型的成员表示对应的 原数据帧成员值是否无效。
示例代码
下面的代码创建一个包含无效数据(NaN)的DataFrame对象:
>>> df = pd.DataFrame({'age': [5, 6, np.NaN],
... 'born': [pd.NaT, pd.Timestamp('1939-05-27'),
... pd.Timestamp('1940-04-25')],
... 'name': ['Alfred', 'Batman', ''],
... 'toy': [None, 'Batmobile', 'Joker']})
>>> df
age born name toy
0 5.0 NaT Alfred None
1 6.0 1939-05-27 Batman Batmobile
2 NaN 1940-04-25 Joker
下面的代码使用isna()方法检测上述DataFrame对象中的无效值:
>>> df.isna()
age born name toy
0 False True False True
1 False False False False
2 True False False False