"TypeError: data type not understood"比较 dtype np.datetime64



根据此响应,我正在将子类型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

熊猫版本"1.0.2">
numpy版本"1.18.1'
有什么想法吗?感谢

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

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

最新更新