【问题标题】:"TypeError: data type not understood" comparing dtype np.datetime64“TypeError:数据类型不理解”比较 dtype np.datetime64
【发布时间】:2020-03-17 07:55:46
【问题描述】:

根据response,我将子类型 datetime64[ns, US/Central]np.datetime64 进行比较:

        columns = self._obj.columns
        for dtype in self._obj.dtypes:
            print("testing:", dtype)
            if np.issubdtype(dtype, np.datetime64):
               ...
testing: datetime64[ns, US/Central]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-2ddcb445a42c> in <module>
...
...(self, dataframe, *dataframes)
    147         for dtype in self._obj.dtypes:
    148             print("testing:", dtype)
--> 149             if np.issubdtype(dtype, np.datetime64):

...
TypeError: data type not understood

如果在此数据框中运行 head(),我会在该列中得到正常的时间戳:

ts
0   2020-02-22 12:11:40-06:00   NaN
1   2020-02-22 12:11:41-06:00   NaN

pandas.版本 '1.0.2'
numpy.版本 '1.18.1'
有任何想法吗?谢谢

【问题讨论】:

  • 你可以在 GitHub 中打开一个问题,我觉得应该可以。看看你能不能把它变成一个纯粹的 numpy 问题(通过.values 访问底层的 numpy 数组),并在那里而不是在 pandas 中提出它:github.com/numpy/numpy
  • 你提出并发布了,它是否在 numpy 中得到修复?另外,如何将时区添加到 numpy datetime64,或者是 pandas?
  • 没关系,一定是熊猫。不过,最新的 numpy 似乎仍然存在这个问题。

标签: python pandas numpy


【解决方案1】:

不理想,但我通过字符串比较解决了这个问题:

if (str(dtype).startswith("datetime64")):
   ...

【讨论】:

    猜你喜欢
    • 2023-03-27
    • 1970-01-01
    • 2020-06-16
    • 2018-05-24
    • 2021-06-11
    • 2020-03-25
    • 2021-07-17
    • 2018-12-01
    • 2019-04-08
    相关资源
    最近更新 更多