hdf5数据库中的不可见数据(使用Python/Pandas/ViTables)

2024-04-27 04:09:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个hdf5数据库,这给我带来了一些麻烦。在

它应该包含3000个表,其中6列(整数和浮点)加上索引(日期)和可变行数(从100到10000000)。在

从昨天开始,当我使用ViTables“查看”数据库时,我错过了数千个表。我以前能在生命中看到他们。但数据仍然存在:我仍然可以通过熊猫访问它们。在

数据组织如下:type/source/id

例如,我可以使用以下方法检索id1和id2:

 with pd.get_store(HDF_DATABASE) as store:
     print store['type1/source1/id1']
     print store['type2/source2/id2']

但从生命中,我看不到type2/source2/id2。在

此外,> print store将列出type1/source1/id1,而不是{}。在

关于如何修复这些“不可见”数据表有什么建议吗?在

编辑:

  • 打字错误
  • Windows 7 32bit/Python 2.7.5/Pandas 0.12.0(和其他 过去的版本)
  • ptdump文件:http://pastebin.com/7mB6bT2T
  • 正如人们所料,我混淆了类型源id
  • 看起来数据不再被引用,但只要数据库不是ptrepack-ed,数据仍然存在

编辑2:

  • 我完全失去了原来的数据库:我不能再访问它了。格式不再被识别。在
  • 用于插入新数据的此语句(以及其他类似语句)返回NaturalNameWarning警告:store.append('equity/bloomberg/4615238QCN_Equity', df)。它不尊重产生警告的自然命名要求。这可能与遇到的问题有关。在

Tags: 数据storeid数据库编辑警告语句hdf5
1条回答
网友
1楼 · 发布于 2024-04-27 04:09:48

示例会话

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”没有执行您认为的那样,它“看起来”像一个文件路径。您需要反斜杠,而不是正斜杠(因为它们依赖于体系结构)。理论上,虽然这是可行的(但是为了避免警告,您可能需要更改这些名称)。在

相关问题 更多 >