Search code examples
pythonpandashdfstore

Pandas Hdf Get table info


Is there any way to get the info of a HDF table using the pandas HDF store?

For example in SQL there is:

SELECT COUNT(*)

I would like to read basic table sizes without having to load the tables itself.


Solution

  • try this:

    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)
    

    available methods

    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
    

    show items

    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