[SOLVED] error name 'dtype' is not defined


I try to compile this code but I get this errror :

NameError: name 'dtype' is not defined

Here is the python code :

# -*- 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

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

Any idea please to help me to resolve this problem?
Thank you


As written by 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

In that case you need e.g.

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


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

Answered By – ntg

Answer Checked By – Willingham (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *