0
如何在hdf5表中更改min_itemsize的所有字符串列?在運行時我不知道我的數據幀結構,因此無法對其進行硬編碼。如何更改pandas hdfstore中所有列的字符串列大小?
如何在hdf5表中更改min_itemsize的所有字符串列?在運行時我不知道我的數據幀結構,因此無法對其進行硬編碼。如何更改pandas hdfstore中所有列的字符串列大小?
請參閱文檔here。
itemsize在第一個附件上創建(並且以後不能更改)。如果沒有指定min_itemsize
,它將是該追加中字符串的最大長度。
In [1]: df = DataFrame({ 'A' : ['foo','bar']})
In [2]: store = pd.HDFStore('test.h5',mode='w')
In [3]: store.append('df',df,min_itemsize=30)
In [4]: store.get_storer('df')
Out[4]: frame_table (typ->appendable,nrows->2,ncols->1,indexers->[index])
In [5]: store.get_storer('df').table
Out[5]:
/df/table (Table(2,)) ''
description := {
"index": Int64Col(shape=(), dflt=0, pos=0),
"values_block_0": StringCol(itemsize=30, shape=(1,), dflt='', pos=1)}
byteorder := 'little'
chunkshape := (1724,)
autoindex := True
colindexes := {
"index": Index(6, medium, shuffle, zlib(1)).is_csi=False}
In [8]: store['df']
Out[8]:
A
0 foo
1 bar
In [6]: store.close()