Reputation: 545
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
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")
Any idea please to help me to resolve this problem? Thank you
Upvotes: 5
Views: 16271
Reputation: 21
I have just realized that I could have used:
from pandas.api.types import is_string_dtype, is_numeric_dtype
Upvotes: 2
Reputation: 14185
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
ordf.colname.dtype
In that case you need e.g.
df['colname'].dtype == np.dtype('datetime64')
or
df.colname.dtype == np.dtype('datetime64')
Upvotes: 5
Reputation: 336
You should use type
instead of dtype
.
type
is a built-in function of python -
https://docs.python.org/3/library/functions.html#type
On the other hand, If data
is a pandas dataframe then you can check the type of a column as follows:
df['colname'].dtype
or df.colname.dtype
Upvotes: 3