首页 > 解决方案 > .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 一起使用哪一个以及为什么要使用?他们每个人与熊猫的主要优点和缺点是什么?

标签: pythonpandasnumpydataframe

解决方案


推荐阅读