python如何检查数据框中的值是不是为nan [重复]

Posted

技术标签:

【中文标题】python如何检查数据框中的值是不是为nan [重复]【英文标题】:python how to check if value in dataframe is nan [duplicate]python如何检查数据框中的值是否为nan [重复] 【发布时间】:2018-07-21 12:05:34 【问题描述】:

有没有办法检查数据帧的特定行和列中的特定值是否为 nan?

我试过 np.isnan(df.loc[no,'LatinDesc']) 其中 no 是第 no 行,但我收到以下错误:

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

【问题讨论】:

【参考方案1】:

您可以为此使用内置的 pandas 功能。举例说明:

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如何检查数据框中的值是不是为nan [重复]的主要内容,如果未能解决你的问题,请参考以下文章