2015-11-02 96 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'

相關問題