Pandas HDF5附加时间序列失败

时间:2016-09-22 11:47:57

标签: pandas append time-series hdf5

通过pandas HDF5可用性(http://pandas.pydata.org/pandas-docs/stable/io.html#io-hdf5)的文档,给出的示例引发了一个错误:

import pandas as pd
import numpy as np

store = pd.HDFStore('store.h5')

np.random.seed(1234)

index = pd.date_range('1/1/2000', periods=8)

df = pd.DataFrame(np.random.randn(8, 3), index=index)

store['df'] = df

df1 = df[0:4]
df2 = df[4:]
store.append('df', df1)
store.append('df', df2)

Traceback (most recent call last):
  File "C:\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2885, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-225-ef7f2e059c6a>", line 1, in <module>
    store.append('df', df1)
  File "C:\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 919, in append
    **kwargs)
  File "C:\Anaconda3\lib\site-packages\pandas\io\pytables.py", line 1252, in _write_to_group
    raise ValueError('Can only append to Tables')
ValueError: Can only append to Tables

这里有什么变化吗?或者我做错了什么?

1 个答案:

答案 0 :(得分:2)

您需要在表格格式中默认启用append,方法是在开头设置以下选项,因为您的商店目前的行为类似于DF

pd.set_option('io.hdf.default_format','table')

Docs