Pandas isna() 和 isnull(),有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52086574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pandas isna() and isnull(), what is the difference?
提问by bakka
Pandas has both isna()
and isnull()
. I usually use isnull()
to detect missing values and have never met the case so that I had to use other than that.
So, when to use isna()
?
Pandas 有isna()
和isnull()
。我通常isnull()
用来检测缺失值,但从未遇到过这种情况,因此我不得不使用其他方法。那么,什么时候使用isna()
?
回答by qsantos
isnull
is an alias for isna
. Literally in the code source of pandas:
isnull
是 的别名isna
。从字面上看,在pandas的代码源中:
isnull = isna
Indeed:
的确:
>>> pd.isnull
<function isna at 0x7fb4c5cefc80>
So I would recommend using isna
.
所以我会推荐使用isna
.
回答by Tam Le
The documentation for both is literally identical.
两者的文档实际上是相同的。
pandas.isna() : https://pandas.pydata.org/pandas-docs/stable/generated/pandas.isna.html#pandas.isna
pandas.isna() : https://pandas.pydata.org/pandas-docs/stable/generated/pandas.isna.html#pandas.isna
pandas.isnull() : https://pandas.pydata.org/pandas-docs/stable/generated/pandas.isnull.html#pandas.isnull
pandas.isnull() : https://pandas.pydata.org/pandas-docs/stable/generated/pandas.isnull.html#pandas.isnull
In here, it even says DataFrame.isnull is an alias of isna in See also section.
在这里,它甚至说 DataFrame.isnull 是另见部分 isna 的别名。
pandas.DataFrame.isnull(): https://pandas-docs.github.io/pandas-docs-travis/generated/pandas.DataFrame.isnull.html#pandas.DataFrame.isnull
pandas.DataFrame.isnull(): https://pandas-docs.github.io/pandas-docs-travis/generated/pandas.DataFrame.isnull.html#pandas.DataFrame.isnull
Therefore, they must be the same thing, like np.nan, np.NaN, np.NAN.
因此,它们必须是相同的东西,例如 np.nan、np.NaN、np.NAN。
回答by Jyoti Prasad Pal
They both are same. As a best practice, always prefer to use isna()
over isnull()
.
他们都是一样的。作为最佳实践,总是更喜欢使用isna()
over isnull()
。
It is easy to remember what isna()
is doing because when you look at numpy method np.isnan()
, it checks NaN
values. In pandas there are other similar method names like dropna()
, fillna()
that handles missing values and it always helps to remember easily.
很容易记住isna()
正在做什么,因为当您查看 numpy method 时np.isnan()
,它会检查NaN
值。在 Pandas 中,还有其他类似的方法名称,例如dropna()
,fillna()
用于处理缺失值,并且总是有助于轻松记住。