그냥 시도해야합니다.
In [22]: df = DataFrame(np.random.randn(5,2),columns=['A','B'])
In [23]: store = pd.HDFStore('test.h5',mode='w')
In [24]: store.append('df_only_indexables',df)
In [25]: store.append('df_with_data_columns',df,data_columns=True)
In [26]: store.append('df_no_index',df,data_columns=True,index=False)
In [27]: store
Out[27]:
<class 'pandas.io.pytables.HDFStore'>
File path: test.h5
/df_no_index frame_table (typ->appendable,nrows->5,ncols->2,indexers->[index],dc->[A,B])
/df_only_indexables frame_table (typ->appendable,nrows->5,ncols->2,indexers->[index])
/df_with_data_columns frame_table (typ->appendable,nrows->5,ncols->2,indexers->[index],dc->[A,B])
In [28]: store.close()
당신은 자동으로 쿼리 가능한 열로 저장된 프레임의 인덱스를 얻을. 기본적으로 다른 열은 쿼리 할 수 없습니다.
data_columns=True
또는 data_columns=list_of_columns
을 지정하면 이러한 값은 별도로 저장되고 이후에 쿼리 할 수 있습니다.
당신이 다음 PyTables
인덱스가 자동으로 쿼리 가능한 열 (예. index
및/또는 data_columns
)를 위해 만들어지지 않습니다 index=False
를 지정합니다.
색인이 생성되는 실제 색인 (PyTables
색인)을 보려면 아래 출력을 참조하십시오. colindexes
은 실제로 생성 된 PyTables
색인이있는 열을 정의합니다. (나는 그것을 약간 잘라 냈다).
/df_no_index/table (Table(5,)) ''
description := {
"index": Int64Col(shape=(), dflt=0, pos=0),
"A": Float64Col(shape=(), dflt=0.0, pos=1),
"B": Float64Col(shape=(), dflt=0.0, pos=2)}
byteorder := 'little'
chunkshape := (2730,)
/df_no_index/table._v_attrs (AttributeSet), 15 attributes:
[A_dtype := 'float64',
A_kind := ['A'],
B_dtype := 'float64',
B_kind := ['B'],
CLASS := 'TABLE',
FIELD_0_FILL := 0,
FIELD_0_NAME := 'index',
FIELD_1_FILL := 0.0,
FIELD_1_NAME := 'A',
FIELD_2_FILL := 0.0,
FIELD_2_NAME := 'B',
NROWS := 5,
TITLE := '',
VERSION := '2.7',
index_kind := 'integer']
/df_only_indexables/table (Table(5,)) ''
description := {
"index": Int64Col(shape=(), dflt=0, pos=0),
"values_block_0": Float64Col(shape=(2,), dflt=0.0, pos=1)}
byteorder := 'little'
chunkshape := (2730,)
autoindex := True
colindexes := {
"index": Index(6, medium, shuffle, zlib(1)).is_csi=False}
/df_only_indexables/table._v_attrs (AttributeSet), 11 attributes:
[CLASS := 'TABLE',
FIELD_0_FILL := 0,
FIELD_0_NAME := 'index',
FIELD_1_FILL := 0.0,
FIELD_1_NAME := 'values_block_0',
NROWS := 5,
TITLE := '',
VERSION := '2.7',
index_kind := 'integer',
values_block_0_dtype := 'float64',
values_block_0_kind := ['A', 'B']]
/df_with_data_columns/table (Table(5,)) ''
description := {
"index": Int64Col(shape=(), dflt=0, pos=0),
"A": Float64Col(shape=(), dflt=0.0, pos=1),
"B": Float64Col(shape=(), dflt=0.0, pos=2)}
byteorder := 'little'
chunkshape := (2730,)
autoindex := True
colindexes := {
"A": Index(6, medium, shuffle, zlib(1)).is_csi=False,
"index": Index(6, medium, shuffle, zlib(1)).is_csi=False,
"B": Index(6, medium, shuffle, zlib(1)).is_csi=False}
/df_with_data_columns/table._v_attrs (AttributeSet), 15 attributes:
[A_dtype := 'float64',
A_kind := ['A'],
B_dtype := 'float64',
B_kind := ['B'],
CLASS := 'TABLE',
FIELD_0_FILL := 0,
FIELD_0_NAME := 'index',
FIELD_1_FILL := 0.0,
FIELD_1_NAME := 'A',
FIELD_2_FILL := 0.0,
FIELD_2_NAME := 'B',
NROWS := 5,
TITLE := '',
VERSION := '2.7',
index_kind := 'integer']
따라서 열을 쿼리하려면 data_column
으로 지정하십시오. 그렇게하지 않으면 dtype (빠른 공간/적은 공간)에 의해 블록에 저장됩니다.
일반적으로 검색을 위해 열을 색인화하려고하지만 하나의 저장소에 여러 파일을 추가하는 경우 일반적으로 색인 생성을 해제하고 마지막 단계에서 수행합니다 (매우 비싸기 때문에 당신이가는 동안 창조하십시오).
질문에 대해서는 the cookbook을 참조하십시오.
index = True를 설정하는 용도는 무엇입니까? 필자는 data_columns = True, index = False로 설정할 수 있으며 여전히 해당 열을 사용하여 테이블을 쿼리 할 수 있다고 생각합니다. – Michael
수 있지만 실제로 모든 인덱스에 대한 선형 스캔을 유발하는 인덱스를 갖는 이점을 얻지는 못합니다 . index = False는 추가 할 때 유용합니다. 예를 들어, 여러 번 추가하면 인덱스를 추가하는 것이 더 효율적입니다. (많은 양의 데이터에 대해) – Jeff
추가를 마치면 인덱스를 어떻게 구성합니까? 판다 문서에 대한 예를 찾을 수 없었습니다. 도와 줘서 고마워. – Michael