在Pandas中,`isnull()`和`isna()`函数在功能上是相同的,它们都用于检查数据中是否存在缺失值¹²³⁴⁵。这两个函数都会返回一个布尔类型的对象(例如,Series或DataFrame),该对象的形状与原始数据相同,如果原始数据中的元素是缺失值(例如,NaN或None),那么对应的布尔值为True¹²³⁴⁵。
这两个函数存在的原因是为了向用户提供更多的选择¹²³⁴⁵。在R语言中,`na`和`null`是两种不同的东西,但在Python的Pandas中,这两个概念都被表示为NaN¹²³⁴⁵。因此,Pandas提供了`isna()`和`isnull()`两个函数,它们都可以用于检查数据中是否存在NaN¹²³⁴⁵。
以下是一个使用`isnull()`和`isna()`的例子¹²³⁴⁵:
```python
import pandas as pd
import numpy as np
# 创建一个包含缺失值的DataFrame
df = pd.DataFrame({
'A': [1, 2, np.nan],
'B': [4, np.nan, 6]
})
# 使用isnull()检查缺失值
print(df.isnull())
# 使用isna()检查缺失值
print(df.isna())
```
这两个函数的输出是相同的¹²³⁴⁵。希望这个解释对你有所帮助!
源: 与必应的对话, 2023/11/27
(1) Pandas.DataFrame isna()方法和isnull()方法的区别 - 简书. https://www.jianshu.com/p/2f1d85e47339.
(2) Pandas中pd.isnull与pd.isna的关系 - CSDN博客. https://blog.csdn.net/Jason_WangYing/article/details/109481883.
(3) Pandas isna()和isnull()函数:有何不同 - 极客教程. https://geek-docs.com/pandas/pandas-questions/587_pandas_pandas_isna_and_isnull_what_is_the_difference.html.
(4) Pandas isna()和isnull()|极客笔记. https://deepinout.com/pandas/pandas-questions/587_pandas_pandas_isna_and_isnull_what_is_the_difference.html.
(5) Python学习笔记:空值、无穷值判断之isna、isnull、isfinite - Hider1214 - 博客园. https://www.cnblogs.com/hider/p/16640016.html.
(6) undefined. https://datascience.stackexchange.com/questions/37878/difference-between-isna-and-isnull-in-pandas.
(7) undefined. https://www.r-bloggers.com/r-na-vs-null/.
(8) undefined. https://github.com/pandas-dev/pandas/blob/master/pandas/core/dtypes/missing.py.