Python HDFStore异常:找不到正确的atom类型:基本情况
我所面临的问题与中提到的问题相同 我把它简化为熊猫文档中给出的一个例子 本例中的要点是Python HDFStore异常:找不到正确的atom类型:基本情况,python,pandas,hdf5,hdfstore,Python,Pandas,Hdf5,Hdfstore,我所面临的问题与中提到的问题相同 我把它简化为熊猫文档中给出的一个例子 本例中的要点是向HDFStore追加数据帧,其中包含一些缺少的值。当我使用示例代码时,我最终得到了一个原子类型错误 df_mixed Out[103]: A B C bool datetime64 int string 0 -0.065617 -0.062644 -0.004758 True 2001-01-02 00:00:00 1
向HDFStore
追加数据帧
,其中包含一些缺少的值。当我使用示例代码时,我最终得到了一个原子类型错误
df_mixed
Out[103]:
A B C bool datetime64 int string
0 -0.065617 -0.062644 -0.004758 True 2001-01-02 00:00:00 1 string
1 1.444643 1.664311 -0.189095 True 2001-01-02 00:00:00 1 string
2 0.569412 -0.077504 -0.125590 True 2001-01-02 00:00:00 1 string
3 NaN NaN 0.563939 True NaN 1 NaN
4 NaN NaN -0.618218 True NaN 1 NaN
5 NaN NaN 1.477307 True NaN 1 NaN
6 -0.287331 0.984108 -0.514628 True 2001-01-02 00:00:00 1 string
7 -0.244192 0.239775 0.861359 True 2001-01-02 00:00:00 1 string
store=HDFStore('df.h5')
store.append('df_mixed', df_mixed, min_itemsize={'values':50})
...
Exception: cannot find the correct atom type -> [dtype->object,items->Index([datetime64, string], dtype=object)] object of type 'Timestamp' has no len()
如果我按照链接帖子(Jeff的回答)中的建议,对有问题的类型(实际上是对象
类型)强制执行dtype
,我仍然会得到相同的错误。我错过了什么
dtypes = [('datetime64', '|S20'), ('string', '|S20')]
store=HDFStore('df.h5')
store.append('df_mixed', df_mixed, dtype=dtypes, min_itemsize={'values':50})
...
Exception: cannot find the correct atom type -> [dtype->object,items->Index([datetime64, string], dtype=object)] object of type 'Timestamp' has no len()
谢谢你的见解
已解决
我使用的是pandas
0.10,然后切换到0.11-dev。正如杰夫推断的那样,问题在于NaN与NaT的较量
前熊猫版制作
df_mixed.ix[3:5,['A', 'B', 'string', 'datetime64']] = np.nan such that
2 0.569412 -0.077504 -0.125590 True 2001-01-02 00:00:00 1 string
3 NaN NaN 0.563939 True NaN 1 NaN
而后一个版本
2 0.569412 -0.077504 -0.125590 True 2001-01-02 00:00:00 1 string
3 NaN NaN 0.563939 True NaT 1 NaN
问题在于datetime64[ns]系列中的NaN。这些一定是NaT。你是如何构建这个框架的?你用的是什么版本
你能使用0.11-dev吗?(这里还有几个选项)。试试这个:
df['datetime64']=Series(df['datetime64'],dtype='M8[n2]')
此外,这里还有一些更有用的链接:您正确地升级到了0-11以获得正确的NaT。我据此编辑了我的文章。谢谢