熊猫Hdf获取表格信息

时间:2016-06-23 08:13:37

标签: python pandas hdfstore

有没有办法使用pandas HDF商店获取HDF表的信息?

例如,在SQL中有:

SELECT COUNT(*)

我想阅读基本的表格大小,而不必自己加载表格。

1 个答案:

答案 0 :(得分:3)

试试这个:

In [4]: %paste
store_path = r'c:/temp/.data/test.h5'
store_key = 'test'

df.to_hdf(store_path, key=store_key, mode='w', format='t', complib='zlib', complevel=4)
## -- End pasted text --

In [5]: store =  pd.HDFStore(store_path)

可用方法

In [6]: store.
store.append                store.flush                 store.items                 store.root
store.append_to_multiple    store.get                   store.iteritems             store.select
store.close                 store.get_node              store.keys                  store.select_as_coordinates
store.copy                  store.get_storer            store.open                  store.select_as_multiple
store.create_table_index    store.groups                store.put                   store.select_column
store.filename              store.is_open               store.remove

显示项目

In [6]: store.items
Out[6]:
<bound method HDFStore.items of <class 'pandas.io.pytables.HDFStore'>
File path: c:/temp/.data/test.h5
/test            frame_table  (typ->appendable,nrows->1000000,ncols->3,indexers->[index])>

In [8]: store.append('test_indexed', df, data_columns=df.columns)

In [9]: store.items
Out[9]:
<bound method HDFStore.items of <class 'pandas.io.pytables.HDFStore'>
File path: c:/temp/.data/test.h5
/test                    frame_table  (typ->appendable,nrows->1000000,ncols->3,indexers->[index])
/test_indexed            frame_table  (typ->appendable,nrows->1000000,ncols->3,indexers->[index],dc->[A,B,C])>

Docs

相关问题