微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python 类型检查:int vs int64,float vs float64

如何解决Python 类型检查:int vs int64,float vs float64

在 Python 中,我想检查数据框中的某些字段值是否是正确的类型。 所以,我试过这样:

t2check = isinstance(df['T2'][0],float)
print("t2check={}  type={}".format(t2check,type(df['T2'][0]))) 

我得到的回报是 t2check=True type=<class 'numpy.float64'>

so:在检查“float”时,它返回了 numpy.float64,并表示相等。好的。

然而,在对整数值进行类似检查时,我得到了这个:

    passcheck = isinstance(df['Pass'][0],int)
    print("passcheck={}  type={}".format(passcheck,type(df['Pass'][0])))

当我运行它时,我得到 passcheck=False type=<class 'numpy.int64'>

在这里,它说字段值不是“int”——而是一个 numpy.int64。

它不适合我。 为什么它松散地等同于浮点数,而与 int 的定义紧密相关?

我也试过了 passcheck64 = isinstance(df['Pass'][0],numpy.int64) 但这也返回了 False ......

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。