使用pytables modu将pandas数据帧写入hdf5

2024-06-26 00:17:18 发布

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

在下面的示例中,我尝试以h5文件格式存储多索引pandas.DataFrame

import pandas as pd
import numpy as np
store = pd.HDFStore('c:/temp/example.h5')
idx = pd.MultiIndex.from_arrays([['first']*3,['one','two','three']], names = ['outer','inner'])
abc = pd.DataFrame(np.random.randint(1,100,9).reshape(-1,3), index = idx, columns = list('abc'))

如果我试图存储上面的dataframe('abc')进行存储,就会得到一个错误,如下所示

^{pr2}$

我以前没有遇到过这个错误,可能是和pytable的版本更新有关。我目前使用的是3.2.2版。有什么可以替代的解决方案来存储h5格式的数据帧吗?在


Tags: storeimportnumpy示例dataframepandasas错误