0
点赞
收藏
分享

微信扫一扫

python判断值是否为NaN或者None

潇湘落木life 2022-02-15 阅读 148
def isNaNo(sth):
    '''
    NaN或None返回True,其他情况返回Flase
    '''
    if not sth:
        return True
    if isinstance(sth, float):
        if np.isnan(sth):
            return True
    return False

if __name__ == '__main__':
    import numpy as np

    str_no = np.nan
    flag = isNaNo(str_no)
    print(flag)

举报

相关推荐

0 条评论