gpt4 book ai didi

python - 错误名称 'dtype' 未定义

转载 作者:太空狗 更新时间:2023-10-30 02:37:21 25 4
gpt4 key购买 nike

我尝试编译这段代码,但我得到了这个错误:

NameError: name 'dtype' is not defined

这是python代码:

# -*- coding: utf-8 -*-
from __future__ import division
import pandas as pd
import numpy as np
import re
import missingno as msno
from functools import partial
import seaborn as sns
sns.set(color_codes=True)


if dtype(data.OPP_CREATION_DATE)=="datetime64[ns]":
print("OPP_CREATION_DATE is of datetime type")
else:
print("warning: the type of OPP_CREATION_DATE is not datetime, please fix this")

有什么想法可以帮我解决这个问题吗?谢谢

最佳答案

由 Amr Keleg 撰写,

If data is a pandas dataframe then you can check the type of a column as follows:
df['colname'].dtype or df.colname.dtype

在那种情况下你需要例如

df['colname'].dtype ==  np.dtype('datetime64')

df.colname.dtype ==  np.dtype('datetime64')

关于python - 错误名称 'dtype' 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50388396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com