This question already has answers here:
How to check if any value is NaN in a Pandas DataFrame
                                
                                    (20个答案)
                                
                        
                                2年前关闭。
            
                    
有没有一种方法可以检查数据帧的特定行和列中的特定值是否为nan?

我尝试了np.isnan(df.loc [no,'LatinDesc'])
行号为否,但出现以下错误:

输入类型不支持ufunc'isnan',并且根据强制转换规则“ safe”不能将输入安全地强制为任何受支持的类型

最佳答案

您可以为此使用内置的熊猫功能。为了显示:

import pandas as pd
import numpy as np

df = pd.DataFrame({'col1': np.random.rand(100),
              'col2': np.random.rand(100)})

# create a nan value in the 10th row of column 2
df.loc[10, 'col2'] = np.nan

pd.isnull(df.loc[10, :]) # will give true for col2

关于python - python如何检查数据帧中的值是否为nan ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48727515/

10-12 19:14