【问题标题】:TypeError: read_hdf() takes exactly 2 arguments (1 given)TypeError: read_hdf() 正好需要 2 个参数(1 个给定)
【发布时间】:2015-01-21 18:10:25
【问题描述】:

当密钥未知时,如何使用pandas.read_hdf 打开 HDF5 文件?

from pandas.io.pytables import read_hdf
read_hdf(path_or_buf, key)
pandas.__version__ == '0.14.1'

这里的关键参数是未知的。谢谢

【问题讨论】:

    标签: python pandas hdf5 pytables


    【解决方案1】:

    在能够使用online docs 编写示例之前,我从未使用过 hdf 文件:

    In [59]:
    # create a temp df and store it
    df_tl = pd.DataFrame(dict(A=list(range(5)), B=list(range(5))))
    df_tl.to_hdf('store_tl.h5','table',append=True)
    In [60]:
    # we can simply read it again and the keys are displayed
    store = pd.HDFStore('store_tl.h5')
    # keys will be displayed in the output
    store
    Out[60]:
    <class 'pandas.io.pytables.HDFStore'>
    File path: store_tl.h5
    /table            frame_table  (typ->appendable,nrows->5,ncols->2,indexers->[index])
    In [61]:
    # read it back in again
    t = pd.read_hdf('store_tl.h5', 'table')
    t
    Out[61]:
       A  B
    0  0  0
    1  1  1
    2  2  2
    3  3  3
    4  4  4
    

    所以基本上只需使用HDFStore 加载它并传递路径,然后仅显示对象就会在输出中打印键。

    【讨论】:

      【解决方案2】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-18
        • 1970-01-01
        • 1970-01-01
        • 2013-06-12
        • 2013-04-07
        • 1970-01-01
        相关资源
        最近更新 更多