Pandas不修改默认的hdf格式

时间:2014-03-05 13:45:20

标签: python pandas hdf5

我正在尝试将数据存储到hdf格式,并希望将默认数据类型设置为表,以便稍后查询。

我使用的是基本代码:

import pandas as pd
from numpy import random as R
pd.set_option('io.hdf.default_format','table')

s = pd.Series(R.randn(5), index=['a', 'b', 'c', 'd', 'e'])
store = pd.HDFStore('store.h5')
store['s'] = s
print store['s']

a = pd.read_hdf('store.h5','s',where="index=='a'")
print a

然而,它输出

Traceback (most recent call last):
  File "C:\Users\User\Documents\Project work\GalaxyFitting\tests\pandas_test.py", line 3, in <module>
    pd.set_option('io.hdf.default_format','table')
  File "C:\python27\lib\site-packages\pandas\core\config.py", line 230, in __call__
    return self.__func__(*args, **kwds)
  File "C:\python27\lib\site-packages\pandas\core\config.py", line 143, in _set_option
    _set_multiple_options(args, silent)
  File "C:\python27\lib\site-packages\pandas\core\config.py", line 114, in _set_multiple_options
    _set_single_option(k, v, silent)
  File "C:\python27\lib\site-packages\pandas\core\config.py", line 98, in _set_single_option
    key = _get_single_key(pat, silent)
  File "C:\python27\lib\site-packages\pandas\core\config.py", line 76, in _get_single_key
    raise KeyError('No such keys(s)')
KeyError: 'No such keys(s)'
[Finished in 0.8s]

为什么会这样?我所做的就是从the documentation

复制

由于

1 个答案:

答案 0 :(得分:2)

此功能在0.13中引入。因此,您需要最少的pandas版本,请参阅here

请注意,主要文档未提及此最低版本要求。