Python Pandas - 检查系列中的所有值是否为 NaN

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33147158/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 12:51:40  来源:igfitidea点击:

Pandas - check if ALL values are NaN in Series

pythonpandasnullnanseries

提问by Boosted_d16

I have a data series which looks like this:

我有一个如下所示的数据系列:

print mys

id_L1
2       NaN
3       NaN
4       NaN
5       NaN
6       NaN
7       NaN
8       NaN

I would like to check is all the values are NaN.

我想检查所有值是否都是 NaN。

My attempt:

我的尝试:

pd.isnull(mys).all()

Output:

输出:

True

Is this the correct way to do it?

这是正确的方法吗?

采纳答案by Andrew Rosenfeld

Yes, that's correct, but I think a more idiomatic way would be:

是的,这是正确的,但我认为更惯用的方式是:

mys.isnull().all()

回答by Reeves

This will check for all columns..

这将检查所有列..

mys.isnull().values.all(axis=0)