python - .isnull() vs .isna() 用于熊猫
问题描述
.isnull()
与.isna()
熊猫相比。
示例代码:
import pandas as pd
import numpy as np
df = pd.DataFrame({ 'object': ['a', 'b', 'c',pd.NA],
'numeric': [1, 2, np.nan , 4],
})
创建如下所示的数据框df
:
| | object | numeric | categorical |
|---:|:---------|----------:|:--------------|
| 0 | a | 1 | d |
| 1 | b | 2 | nan |
| 2 | c | nan | f |
| 3 | <NA> | 4 | g |
测试.isnull()
和.isna()
:
pd.isnull(df.iloc[3,0])
Out[165]: True
pd.isnull(df.iloc[2,1])
Out[166]: True
pd.isna(df.iloc[3,0])
Out[167]: True
pd.isna(df.iloc[2,1])
Out[168]: True
在这里两者都.isnull()
给出.isna()
相同的结果。
问题:与 pandas 一起使用哪一个以及为什么要使用?他们每个人与熊猫的主要优点和缺点是什么?
解决方案
推荐阅读
- windows - PermissionError: [WinError 5] 安装 conda 后拒绝 pytest 访问
- html - 按钮内的分词
- c - 我的函数中的第二个 scanf 不起作用
- google-sheets - 删除特定字符后的所有数字和字母
- sql - SQLite3 - 从特定用户的愿望清单中打印成本最低的书籍
- regex - 正则表达式(组) - 单词验证
- aws-fargate - 如何更改 ESC/Fargate 中的环境变量?
- javascript - 为什么我不能发出这个 axios DELETE 请求?
- node.js - 将 grunt 任务转换为 package.json 中的 npm 脚本
- swift - 相机内在分辨率与真实屏幕分辨率