Using pandas/pytables, a list of keys can be easily returned using store.keys()
.
>>> store.keys()
['/df_coord', '/metaFrame']
Using the standard dictionary check to see if a key exists, if 'df_coord' in store.keys():
, returns false unless the /
is included. Is there another simple way to evaluate for the existence of a key without having to join strings?
Check against the store itself; they .keys()
returns a string dictionary of the exact keys.
In [1]: store = pd.HDFStore('test.h5',mode='w')
In [2]: store['foo'] = DataFrame(np.random.randn(10,2))
In [3]: store['bar'] = DataFrame(np.random.randn(10,2))
In [4]: store
Out[4]:
<class 'pandas.io.pytables.HDFStore'>
File path: test.h5
/bar frame (shape->[10,2])
/foo frame (shape->[10,2])
In [5]: 'bar' in store
Out[5]: True
In [6]: 'foo' in store
Out[6]: True
In [7]: '/foo' in store
Out[7]: True
In [8]: 'bah' in store
Out[8]: False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With