使用pandas / pytables,可以使用轻松返回键列表store.keys()
。
>>> store.keys()
['/df_coord', '/metaFrame']
使用标准字典检查以查看键是否存在,if 'df_coord' in store.keys():
除非/
包含,否则返回false 。是否有另一种简单的方法可以评估键是否存在而不必连接字符串?
检查商店本身;它们.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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句