使用pandas返回hdf文件中所有数据集的列表

Grr*_*Grr 10 python pandas hdf

这可能是一个愚蠢的问题,但我还没有在熊猫文档或其他地方找到答案.在之前已经提出了同样的问题.但唯一的答案是看看大熊猫文档,正如我所说的那样,没有提供这个问题的答案.

我希望能够构建一个包含多个数据集的hdf文件.一旦关闭了这个hdf,我希望能够列出其中包含的每个数据集.例如:

import pandas as pd
import numpy as np

store = pd.HDFStore('test.h5')
df1 = pd.DataFrame(np.random.randn(10,2), columns=list('AB')
df2 = pd.DataFrame(np.random.randn(10,2), columns=list('AB')
store['df1'] = df1
store['df2'] = df2
print(store)
Run Code Online (Sandbox Code Playgroud)

返回:

<class 'pandas.io.pytables.HDFStore'>
File path: test.h5
/df1           frame          (shape->[10,2])
/df2           frame          (shape->[10,2])
Run Code Online (Sandbox Code Playgroud)

但是,如果您关闭hdf store.close()然后尝试使用pd.read_hdf()以下错误返回它:

ValueError: key must be provided when HDF contains multiple datasets.
Run Code Online (Sandbox Code Playgroud)

有没有办法返回所有这些数据集的列表?

在此先感谢您的帮助!

Sto*_*ica 10

就在这里.

store = pd.HDFStore('test.h5')
print(store)

<class 'pandas.io.pytables.HDFStore'>
File path: test.h5
/df1           frame          (shape->[10,2])
/df2           frame          (shape->[10,2])
Run Code Online (Sandbox Code Playgroud)