2015-11-02 60 views
1

我想读取先前使用PyTables创建的h5文件。使用带有表格格式和数据列的pytables创建HDF5文件

该文件使用Pandas读取,并与一些条件,像这样:

pd.read_hdf('myH5file.h5', 'anyTable', where='some_conditions') 

从另一个问题,我已被告知,为了对H5文件是“可查询”与read_hdf's where说法它必须写在table format,此外,一些列必须声明为data columns

我在PyTables文档中找不到任何关于它的信息。

有关PyTable的create_table方法的文档没有提供任何有关它的信息。

所以,现在,如果我尝试使用类似的东西在我的H5文件createed与PyTables我得到如下:

>>> d = pd.read_hdf('test_file.h5','basic_data', where='operation==1') 
C:\Python27\lib\site-packages\pandas\io\pytables.py:3070: IncompatibilityWarning: 
where criteria is being ignored as this version [0.0.0] is too old (or 
not-defined), read the file in and write it out to a new file to upgrade (with 
the copy_to method) 

    warnings.warn(ws, IncompatibilityWarning) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "C:\Python27\lib\site-packages\pandas\io\pytables.py", line 323, in read_hdf 
    return f(store, True) 
    File "C:\Python27\lib\site-packages\pandas\io\pytables.py", line 305, in <lambda> 
    key, auto_close=auto_close, **kwargs) 
    File "C:\Python27\lib\site-packages\pandas\io\pytables.py", line 665, in select 
    return it.get_result() 
    File "C:\Python27\lib\site-packages\pandas\io\pytables.py", line 1359, in get_result 
    results = self.func(self.start, self.stop, where) 
    File "C:\Python27\lib\site-packages\pandas\io\pytables.py", line 658, in func 
    columns=columns, **kwargs) 
    File "C:\Python27\lib\site-packages\pandas\io\pytables.py", line 3968, in read 
    if not self.read_axes(where=where, **kwargs): 
    File "C:\Python27\lib\site-packages\pandas\io\pytables.py", line 3196, in read_axes 
    values = self.selection.select() 
    File "C:\Python27\lib\site-packages\pandas\io\pytables.py", line 4482, in select 
    start=self.start, stop=self.stop) 
    File "C:\Python27\lib\site-packages\tables\table.py", line 1567, in read_where 
    self._where(condition, condvars, start, stop, step)] 
    File "C:\Python27\lib\site-packages\tables\table.py", line 1528, in _where 
    compiled = self._compile_condition(condition, condvars) 
    File "C:\Python27\lib\site-packages\tables\table.py", line 1366, in _compile_condition 
    compiled = compile_condition(condition, typemap, indexedcols) 
    File "C:\Python27\lib\site-packages\tables\conditions.py", line 430, in compile_condition 
    raise _unsupported_operation_error(nie) 
NotImplementedError: unsupported operand types for *eq*: int, bytes 

编辑:

回溯提到关于IncompatibilityWarning东西和版本[0.0.0],但是如果我检查我的熊猫和表格的版本,我得到:

>>> import pandas 
>>> pandas.__version__ 
'0.15.2' 
>>> import tables 
>>> tables.__version__ 
'3.1.1' 

所以,我TOT盟友困惑。

+0

好,您正在使用熊猫读取这个文件,所以文档是[这里](http://pandas.pydata.org/pandas-docs/stable/io的.html#HDF5-pytables)。熊猫可以读取PyTables的“表格”格式。所以不完全清楚你是如何创造的。 – Jeff

+0

杰夫,这个问题不是关于阅读是关于如何使用PyTables创建h5文件,并使表格具有'table'格式并使某些列成为'数据列'以便能够用熊猫读取它们,并且此信息是不在PyTables文档据我所知 – codeKiller

+0

你必须使用熊猫来创建它们:pytables只是一个存储层。请阅读我指出的文档 – Jeff

回答

0

我有同样的问题,这就是我所做的。

  1. 通过PyTables创建一个HDF5文件;
  2. 阅读pandas.read_hdf和使用参数,这样HDF5文件 “里= where_string,列= selected_columns”

  3. 我像下面的警告信息和其他错误信息:

    d: \ Program Files \ Anaconda3 \ lib \ site-packages \ pandas \ io \ pytables.py:3065: IncompatibilityWarning:由于 版本[0.0.0]太旧(或未定义),因此标准被忽略,读入文件并 写出一个新文件进行升级(使用copy_to方法d)

    warnings.warn(WS,IncompatibilityWarning)

  4. 我试图像这样的命令:

    hdf5_store = pd.HDFStore(hdf5_file,模式= 'R')

    h5cpt_store_new = hdf5_store.copy(hdf5_new_file,complevel = 9,complib ='blosc') h5cpt_store_new.close()

  5. 然后像第2步一样运行命令,它可以工作。

    熊猫。版本 '0.17.1'

    表。 版本 '3.2.2'

相关问题