Pandas isnull(~) 方法返回一个布尔掩码,其中 True 设置为 NaN (缺失值),False 设置为非 NaN 。
参数
1.obj | array-like 或 object
用于检查 NaN 的类数组(例如 Series、DataFrame、Numpy 数组、列表等)。
返回值
-
如果提供单个标量对象(例如字符串和数字),则返回单个
boolean。 -
否则,返回布尔掩码,其中
True表示非NaN值,False表示NaN。
例子
标量
pd.isnull("A")
False
pd.isnull(np.NaN)
True
pd.isnull(None)
True
Array-likes
Series
s = pd.Series([1,np.NaN,3])
pd.isnull(s)
0 False
1 True
2 False
dtype: bool
返回类型是布尔值Series。
DataFrame
考虑以下 DataFrame :
df = pd.DataFrame({"A":[np.NaN,2], "B":[3,np.NaN]})
df
A B
0 NaN 3.0
1 2.0 NaN
要检查现有值(非 NaN 值):
pd.isnull(df)
A B
0 True False
1 False True
返回类型是布尔值DataFrame。
注意
Series 和 DataFrames 都有方法 isnull() ,因此可以直接调用 df.isnull() 。
相关用法
- Python NumPy isnumeric方法用法及代码示例
- Python string isnumeric()用法及代码示例
- Python NumPy isnat方法用法及代码示例
- Python math isnan()用法及代码示例
- Python NumPy isneginf方法用法及代码示例
- Python NumPy isnan方法用法及代码示例
- Python isinstance方法用法及代码示例
- Python string isidentifier()用法及代码示例
- Python calendar isleap()用法及代码示例
- Python math isclose()用法及代码示例
- Python NumPy isalnum方法用法及代码示例
- Python string isupper()用法及代码示例
- Python string isalnum()用法及代码示例
- Python isdisjoint()用法及代码示例
- Python NumPy isposinf方法用法及代码示例
- Python issubclass()用法及代码示例
- Python NumPy isreal方法用法及代码示例
- Python string istitle()用法及代码示例
- Python NumPy isclose方法用法及代码示例
- Python NumPy iscomplexobj方法用法及代码示例
- Python string isalpha()用法及代码示例
- Python NumPy isrealobj方法用法及代码示例
- Python NumPy isfinite方法用法及代码示例
- Python string isdigit()用法及代码示例
- Python NumPy isalpha方法用法及代码示例
注:本文由纯净天空筛选整理自Isshin Inada大神的英文原创作品 Pandas | isnull method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
