Python中的 pandas.isna()函数
此方法用于检测类数组对象的缺失值。此函数采用标量或类数组对象并指示是否缺少值(数字数组中的“NaN”,对象数组中的“None”或“NaN”,datetimelike 中的“NaT”)。
Syntax : pandas.isna(obj)
Argument :
- obj : scalar or array-like, Object to check for null or missing values.
以下是上述方法的实现以及一些示例:
示例 1:
Python3
# importing package
import numpy
import pandas
# string "deep" is not nan value
print(pandas.isna("deep"))
# numpy.nan represents a nan value
print(pandas.isna(numpy.nan))
Python3
# importing package
import numpy
import pandas
# create and view data
array = numpy.array([[1, numpy.nan, 3],
[4, 5, numpy.nan]])
print(array)
# numpy.nan represents a nan value
print(pandas.isna(array))
输出 :
False
True
示例 2:
Python3
# importing package
import numpy
import pandas
# create and view data
array = numpy.array([[1, numpy.nan, 3],
[4, 5, numpy.nan]])
print(array)
# numpy.nan represents a nan value
print(pandas.isna(array))
输出 :
[[ 1. nan 3.]
[ 4. 5. nan]]
[[False True False]
[False False True]]