Ste*_*ray 7 hdf5 pandas hdfstore
我正在使用Pandas,并制作一个HDFStore对象.我计算500列数据,并将其写入表格式HDFStore对象.然后我关闭文件,从内存中删除数据,执行下一个500列(用增加的整数标记),打开商店,然后尝试追加新列.但是,它并不喜欢这样.它给了我一个错误
invalid combinate of [non_index_axes] on appending data [[(1, [500, 501, 502, ...])]] vs current table [[(1, [0, 1, 2, ...])]]
Run Code Online (Sandbox Code Playgroud)
我假设它只允许附加更多行而不是列.那么如何添加更多列?
HDF5文件具有固定的结构,您无法轻松添加列,但解决方法是将不同的DF连接起来并将它们重新写入HDF5文件中。
hdf5_files = ['data1.h5', 'data2.h5', 'data3.h5']
df_list = []
for file in hdf5_files:
df = pd.read_hdf(file)
df_list.append(df)
result = pd.concat(df_list)
# You can now use the result DataFrame to access all of the data from the HDF5 files
Run Code Online (Sandbox Code Playgroud)
这能解决您的问题吗?
提醒一下 HDF5 并不是为高效的追加操作而设计的,如果您需要经常向数据添加新列,您应该考虑数据库系统,恕我直言。