要創建具有4000列和只有4行的幀;稀疏處理是按行進行處理的,所以反向維度。
In [2]: from numpy import *
In [3]: test = pd.DataFrame(ones((4000,4)))
In [4]: test.ix[:,:] = nan
In [5]: test.ix[0,0] = 47
In [6]: test.to_hdf('test3', 'df')
In [7]: test.to_sparse(fill_value=nan).to_hdf('test4', 'df')
In [8]: test.to_pickle('test5')
In [9]: test.to_sparse(fill_value=nan).to_pickle('test6')
In [11]: !ls -sh test3 test4 test5 test6
164K test3 148K test4 160K test5 36K test6
後續。你提供你的店是寫在table
格式,並因此節省了密集的版本(稀疏不支持表格格式,這是非常靈活的,可查詢,請參閱docs。
此外,您可能需要使用節能試驗。您的文件使用稀疏格式的2所不同的表述
所以,這裏有一個樣本會話:
df =
In [1]: df = pd.read_hdf('store_compressed.h5','test')
In [2]: type(df)
Out[2]: pandas.core.frame.DataFrame
In [3]: df.to_sparse(kind='block').to_hdf('test_block.h5','test',mode='w',complib='blosc',complevel=9)
In [4]: df.to_sparse(kind='integer').to_hdf('test_block.h5','test',mode='w',complib='blosc',complevel=9)
In [5]: df.to_sparse(kind='block').to_hdf('test_block.h5','test',mode='w',complib='blosc',complevel=9)
In [6]: df.to_sparse(kind='integer').to_hdf('test_integer.h5','test',mode='w',complib='blosc',complevel=9)
In [7]: df.to_hdf('test_dense_fixed.h5','test',mode='w',complib='blosc',complevel=9)
In [8]: df.to_hdf('test_dense_table.h5','test',mode='w',format='table',complib='blosc',complevel=9)
In [9]: !ls -ltr *.h5
-rwxrwxr-x 1 jreback users 57015522 Feb 6 18:19 store_compressed.h5
-rw-rw-r-- 1 jreback users 30335044 Feb 6 19:01 test_block.h5
-rw-rw-r-- 1 jreback users 28547220 Feb 6 19:02 test_integer.h5
-rw-rw-r-- 1 jreback users 44540381 Feb 6 19:02 test_dense_fixed.h5
-rw-rw-r-- 1 jreback users 57744418 Feb 6 19:03 test_dense_table.h5
IIRC他們是在0.12在to_hdf
的錯誤沒有通過所有的參數通,所以你問題想要使用:
with get_store('test.h5',mode='w',complib='blosc',complevel=9) as store:
store.put('test',df)
這些基本上是存儲爲SparseSeries
集合因此,如果濃度低,不連續的話,就不會像最小盡可能大小去。儘管YMMV,Pandas稀疏套件可以更好地處理較少數量的連續塊。 scipy也提供了一些稀疏的處理工具。
雖然恕我直言,這些都是非常瑣碎的尺寸HDF5文件無論如何,你可以處理的行數巨大;並且可以輕鬆處理文件大小爲10和100的千兆字節(儘管推薦)。
而且你可能會考慮使用一個表格式,如果這確實是,你可以查詢查找表。
添加一個壓縮濾波器,在這裏看到:http://pandas.pydata.org/pandas-docs/dev/io.html#compression – Jeff
具有致密數據幀和complevel = 9和complib =「blosc」,即下降我們從544M到26M。好得多,但仍然跟不上12M。利用稀疏數據幀試圖壓縮拋出一個類型錯誤: '類型錯誤:不能正確地創建用於貯藏器:[_TABLE_MAP] [組 - >/test_sparse(集團)「」,值 - ><類「pandas.sparse.frame.SparseDataFrame '>,table-> True,append-> True,kwargs - > {'encoding':None}]' – jeffalstott
hmm ....這不是正確的格式;它應該用table = False保存;但這也是默認設置。讓我看一看。 – Jeff