【问题标题】: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'' 无法安全地将输入强制转换为任何支持的类型

【问题讨论】:

    标签: python dataframe nan


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2017-07-28
      • 2016-01-12
      • 2020-07-03
      • 2014-11-09
      • 2019-10-20
      • 2017-12-21
      • 2020-02-04
      • 2014-04-15
      • 1970-01-01
      相关资源
      最近更新 更多