本文翻译自:How to check if any value is NaN in a Pandas DataFrame
In Python Pandas, what's the best way to check whether a DataFrame has one (or more) NaN values? 在Python Pandas中,检查DataFrame是否具有一个(或多个)NaN值的最佳方法是什么?
I know about the function pd.isnan
, but this returns a DataFrame of booleans for each element. 我知道函数pd.isnan
,但是这会为每个元素返回一个布尔数据框架。 This post right here doesn't exactly answer my question either. 这篇文章也没有完全回答我的问题。
#1楼
参考:https://stackoom.com/question/1zuA4/如何检查Pandas-DataFrame中的任何值是否为NaN
#2楼
df.isnull().any().any()
应该这样做。
#3楼
You have a couple of options. 你有几个选择。
import pandas as