示例会话
In [1]: store = pd.HDFStore('test.h5')
In [2]: store['node()'] = Series(np.arange(10))
/usr/local/lib/python2.7/site-packages/tables/path.py:99: NaturalNameWarning: object name is not a valid Python identifier: 'node()'; it does not match the pattern ``^[a-zA-Z_][a-zA-Z0-9_]*$``; you will not be able to use natural naming to access this object; using ``getattr()`` will still work, though
NaturalNameWarning)
In [3]: store
Out[3]:
<class 'pandas.io.pytables.HDFStore'>
File path: test.h5
/df frame_table (typ->appendable,nrows->11,ncols->2,indexers->[index],dc->[A,B])
/node() series (shape->[10])
In [4]: store.keys()
Out[4]: ['/df', '/node()']
In [5]: store['node()/foo'] = Series(np.arange(10))
In [6]: store.keys()
Out[6]: ['/df', '/node()', '/node()/foo']
In [7]: store
Out[7]:
<class 'pandas.io.pytables.HDFStore'>
File path: test.h5
/df frame_table (typ->appendable,nrows->11,ncols->2,indexers->[index],dc->[A,B])
/node() series (shape->[10])
/node()/foo series (shape->[10])
In [8]: store['my_type\mysource\id_01_01'] = Series(np.arange(10))
/usr/local/lib/python2.7/site-packages/tables/path.py:99: NaturalNameWarning: object name is not a valid Python identifier: 'my_type\\mysource\\id_01_01'; it does not match the pattern ``^[a-zA-Z_][a-zA-Z0-9_]*$``; you will not be able to use natural naming to access this object; using ``getattr()`` will still work, though
NaturalNameWarning)
In [9]: store
Out[9]:
<class 'pandas.io.pytables.HDFStore'>
File path: test.h5
/df frame_table (typ->appendable,nrows->11,ncols->2,indexers->[index],dc->[A,B])
/my_type\mysource\id_01_01 series (shape->[10])
/node() series (shape->[10])
/node()/foo series (shape->[10])
In [10]: store.keys()
Out[10]: ['/df', '/my_type\\mysource\\id_01_01', '/node()', '/node()/foo']
In [11]: store['my_type/mysource/id_01_01'] = Series(np.arange(10))
In [12]: store
Out[12]:
<class 'pandas.io.pytables.HDFStore'>
File path: test.h5
/df frame_table (typ->appendable,nrows->11,ncols->2,indexers->[index],dc->[A,B])
/my_type\mysource\id_01_01 series (shape->[10])
/node() series (shape->[10])
/node()/foo series (shape->[10])
/my_type/mysource/id_01_01 series (shape->[10])
问题是标识符“my_type\mysource\id_01_01”没有按照你的想法做,它“看起来”像一个文件路径。您需要反斜杠,而不是正斜杠(因为它们取决于架构)。虽然理论上这会起作用(但为了避免警告,您可能需要更改这些名称)。