类型错误:read_hdf()需要精确2个参数(已给出1个)

4

当你不知道 HDF5 文件中的键是什么时,如何使用 pandas.read_hdf 打开 HDF5 文件呢?

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

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

2个回答

4

我以前从未使用过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 加载它并传递路径,然后只需显示对象即可在输出中打印键。


3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接