简体   繁体   English

检查熊猫日期栏

[英]Check date column in pandas

I have this: 我有这个:

dfData['dt']
Out[53]: 
0   2013-01-02
1   2016-10-20
Name: dt, dtype: datetime64[ns]

I try this: 我尝试这样:

dfData['dt'].dtype==np.datetime64
Out[56]: False

I also try this: 我也尝试这样:

isinstance(dfData['dt'], pd.DatetimeIndex)
Out[62]: False

What am I doing wrong? 我究竟做错了什么? How can I identify general date types? 如何识别一般日期类型?

Use function numpy.issubdtype : 使用函数numpy.issubdtype

print (np.issubdtype(dfData['dt'].dtype, np.datetime64))
True

Pandas solution with functions for check dtypes : 具有functions for check dtypes Pandas解决方案:

from pandas.api.types import is_datetime64_any_dtype

print (is_datetime64_any_dtype(dfData['dt'].dtype))
True

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM