【问题标题】:HDFStore Exception: cannot find the correct atom type : a basic caseHDFStore 异常:找不到正确的原子类型:基本情况
【发布时间】:2013-03-18 16:35:08
【问题描述】:

我面临与How to trouble-shoot HDFStore Exception: cannot find the correct atom type 中提出的问题相同的问题。

我将其简化为 pandas 文档 Storing Mixed Types in a Table 中给出的示例。

这个例子中的重点是append 一个DataFrameHDFStore 的一些缺失值。当我使用示例代码时,我最终得到一个atom type error

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 的回答)中的建议对有问题的类型(实际上是 object)强制执行 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 。正如 Jeff 推断的那样,问题在于 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

【问题讨论】:

    标签: python pandas hdf5 hdfstore


    【解决方案1】:

    问题是您的 datetime64[ns] 系列中的 NaN。这些必须是 NaT。你是如何构建这个框架的?你用的是什么熊猫版本?

    你可以使用 0.11-dev 吗? (这里还有几个选项)。试试这个:

    df['datetime64'] = Series(df['datetime64'],dtype='M8[n2]')

    此外,这里还有一些更有用的链接:http://pandas.pydata.org/pandas-docs/dev/cookbook.html#hdfstore

    【讨论】:

    • 您升级到 0-11 以获得正确的 NaT 是对的。我相应地编辑了我的帖子。谢谢
    猜你喜欢
    • 2013-03-07
    • 2013-05-01
    • 2015-07-18
    • 2020-05-11
    • 1970-01-01
    • 1970-01-01
    • 2012-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多