首页 文章

如何从熊猫中读取HDF表?

提问于
浏览
2

我有一个 my_file.h5 文件,据推测,它包含HDF5格式的数据(PyTables) . 我尝试使用pandas读取此文件:

import pandas as pd
store = pd.HDFStore('my_file.h5')

然后我尝试使用 store 对象:

print store

结果我得到:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.7/pandas/io/pytables.py", line 133, in __repr__
    kind = v._v_attrs.pandas_type
  File "/usr/lib/python2.7/dist-packages/tables/attributeset.py", line 302, in __getattr__
    (name, self._v__nodePath)
AttributeError: Attribute 'pandas_type' does not exist in node: '/data'

有人知道我做错了什么吗?问题可能是因为我的 *.h5 不是我认为的那样(不是hdf5格式的数据)吗?

2 回答

  • 3

    在你的 /usr/lib/pymodules/python2.7/pandas/io/pytables.py ,第133行

    kind = v._v_attrs.pandas_type
    

    在我的 pytables.py 中,我明白了

    kind = getattr(n._v_attrs,'pandas_type',None)
    

    通过使用 getattr ,如果没有 pandas_type 属性,则 kind 设置为 None . 我猜我的熊猫版本

    In [7]: import pandas as pd
    
    In [8]: pd.__version__
    Out[8]: '0.10.0'
    

    比你的新 . 如果是这样,修复方法是升级您的 pandas .

  • 2

    我有一张h5 table . 使用独立于pandas的pytables制作并需要将其转换为元组列表然后将其导入df . 这很好听,因为它允许我利用我的pytables索引在输入上运行“where” . 这节省了我读取所有行 .

相关问题