我有一个这样的 HDF 文件:
>>> dataset.store
... <class 'pandas.io.pytables.HDFStore'>
... File path: ../data/data_experiments_01-02-03.h5
... /exp01/user01 frame_table (typ->appendable,nrows->221,ncols->124,indexers->[index])
... /exp01/user02 frame_table (typ->appendable,nrows->163,ncols->124,indexers->[index])
... /exp01/user03 frame_table (typ->appendable,nrows->145,ncols->124,indexers->[index])
... /exp02/user01 frame_table (typ->appendable,nrows->194,ncols->124,indexers->[index])
... /exp02/user02 frame_table (typ->appendable,nrows->145,ncols->124,indexers->[index])
... /exp03/user03 frame_table (typ->appendable,nrows->348,ncols->124,indexers->[index])
... /exp03/user01 frame_table (typ->appendable,nrows->240,ncols->124,indexers->[index])
我想从其中一个实验(exp0Z)中检索所有用户(userXY)并将它们附加到一个大数据帧中。我尝试store.get('exp03')
获得以下错误:
>>> store.get('exp03')
...
... ---------------------------------------------------------------------------
... TypeError Traceback (most recent call last)
... <ipython-input-109-0a2e29e9e0a4> in <module>()
... ----> 1 dataset.store.get('/exp03')
...
... /Library/Python/2.7/site-packages/pandas/io/pytables.pyc in get(self, key)
... 613 if group is None:
... 614 raise KeyError('No object named %s in the file' % key)
... --> 615 return self._read_group(group)
... 616
... 617 def select(self, key, where=None, start=None, stop=None, columns=None,
...
... /Library/Python/2.7/site-packages/pandas/io/pytables.pyc in _read_group(self, group, **kwargs)
... 1277
... 1278 def _read_group(self, group, **kwargs):
... -> 1279 s = self._create_storer(group)
... 1280 s.infer_axes()
... 1281 return s.read(**kwargs)
...
... /Library/Python/2.7/site-packages/pandas/io/pytables.pyc in _create_storer(self, group, format, value, append, **kwargs)
... 1160 else:
... 1161 raise TypeError(
... -> 1162 "cannot create a storer if the object is not existing "
... 1163 "nor a value are passed")
... 1164 else:
...
... TypeError: cannot create a storer if the object is not existing nor a value are passed
我可以通过调用来检索单个用户store.get('exp03/user01')
,所以我想可以迭代store.keys()
并手动附加检索到的数据帧,但我想知道是否可以在一次调用store.get()
或其他类似方法中这样做。
编辑:请注意,数据集是一个包含我的 pandas.HDFstore 的类