【问题标题】:Check date column in pandas检查熊猫中的日期列
【发布时间】:2019-06-14 13:01:34
【问题描述】:

我有这个:

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

我试试这个:

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

我也试试这个:

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

我做错了什么?如何识别一般日期类型?

【问题讨论】:

    标签: python-3.x pandas date


    【解决方案1】:

    使用函数numpy.issubdtype

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

    functions for check dtypes 的 Pandas 解决方案:

    from pandas.api.types import is_datetime64_any_dtype
    
    print (is_datetime64_any_dtype(dfData['dt'].dtype))
    True
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-07
      • 1970-01-01
      • 2020-06-04
      • 1970-01-01
      • 2019-11-28
      • 1970-01-01
      • 2018-09-04
      • 1970-01-01
      相关资源
      最近更新 更多