我使用pandas HDFStore将数据存储在hfd5文件中。
通常情况下,数据一次只附加一个样本,而不是长批次。
我注意到文件增长得相当快,我可以通过ptrepack大大减少它们。
下面是一个小文件的例子。我的应用程序(使用zlib和complevel9)生成的文件有6.7mb大。
/ (RootGroup) ''
/test (Group) ''
/test/table (Table(1042,), shuffle, zlib(1)) ''
description := {
"index": Int64Col(shape=(), dflt=0, pos=0),
"values_block_0": Float64Col(shape=(2,), dflt=0.0, pos=1),
"values_block_1": Int64Col(shape=(1,), dflt=0, pos=2)}
byteorder := 'little'
chunkshape := (2048,)
autoindex := True
colindexes := {
"index": Index(6, medium, shuffle, zlib(1)).is_csi=False}
如果我不带选项重新打包,它会变得更小(71K):
/ (RootGroup) ''
/test (Group) ''
/test/table (Table(1042,)) ''
description := {
"index": Int64Col(shape=(), dflt=0, pos=0),
"values_block_0": Float64Col(shape=(2,), dflt=0.0, pos=1),
"values_block_1": Int64Col(shape=(1,), dflt=0, pos=2)}
byteorder := 'little'
chunkshape := (2048,)
使用时
--complevel=1
或
--complevel=9
,我得到了一个19K的文件。
/ (RootGroup) ''
/test (Group) ''
/test/table (Table(1042,), shuffle, zlib(1)) ''
description := {
"index": Int64Col(shape=(), dflt=0, pos=0),
"values_block_0": Float64Col(shape=(2,), dflt=0.0, pos=1),
"values_block_1": Int64Col(shape=(1,), dflt=0, pos=2)}
byteorder := 'little'
chunkshape := (2048,)
/ (RootGroup) ''
/test (Group) ''
/test/table (Table(1042,), shuffle, zlib(9)) ''
description := {
"index": Int64Col(shape=(), dflt=0, pos=0),
"values_block_0": Float64Col(shape=(2,), dflt=0.0, pos=1),
"values_block_1": Int64Col(shape=(1,), dflt=0, pos=2)}
byteorder := 'little'
chunkshape := (2048,)
这些文件都很小,但我想说的是,只要重新打包,我就可以将整个35GB的数据库缩小到几百MB。
一定是写得不对。
我知道
"hdf5 does not reclaim space" warning
为了附加新数据,我使用
store.append(data_id, data_dataframe)
所以我只附加。我不会删除/写入全部数据。
autoindex := True
colindexes := {
"index": Index(6, medium, shuffle, zlib(1)).is_csi=False}
但我不知道该怎么办。
或者是因为每次修改块时,它都会写入另一个空间,而旧的块空间会丢失?
在这种情况下,我想我的选择是: