2014-09-07 7 views
6

http://pandas.pydata.org/pandas-docs/stable/io.html#indexing인덱싱 및 팬더의 데이터 열/PyTables는

나는 팬더 HDF5 IO의 데이터 열이 개념에 대해 정말 혼란 스러워요. 거기에 대한 정보가 없기 때문에 검색 중 하나에 대해서도 정보가 거의 없습니다. 필자는 HDF5 스토리지와 관련된 대규모 프로젝트에서 팬더로 뛰어 들고 있으므로 이러한 개념에 대해 분명히 알고 싶습니다.

워드 프로세서 말 :

당신은 지정 (인덱스) 당신이 쿼리를 수행 할 할 수 있도록하려면 특정 열 수 있습니다 (즉, 색인 열 이외의 어떤 할 수 있습니다 항상 쿼리). 예를 들어,이 공통적 인 작업을 디스크에서 수행하고이 쿼리와 일치하는 프레임 만 반환하려고한다고 가정합니다. 당신은 data_columns

이 혼동 될 모든 열을 강제로 진정한 data_columns을 = 지정할 수 있습니다

  1. other than the indexable columns, which you can always query : '색인'열은 무엇입니까? 모든 열이 '색인 가능'하지 않습니까? 이 용어는 무엇을 의미합니까?

  2. For instance say you want to perform this common operation, on-disk, and return just the frame that matches this query. 어떻게 Pytable에서 일반적인 쿼리와 다른가? 또는 data_columns의 색인이 있거나 없음?

  3. 인덱스되지 않은 색인 된 열과 data_column 열의 근본적인 차이점은 무엇입니까?

답변

5

그냥 시도해야합니다.

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을 참조하십시오.

+0

index = True를 설정하는 용도는 무엇입니까? 필자는 data_columns = True, index = False로 설정할 수 있으며 여전히 해당 열을 사용하여 테이블을 쿼리 할 수 ​​있다고 생각합니다. – Michael

+0

수 있지만 실제로 모든 인덱스에 대한 선형 스캔을 유발하는 인덱스를 갖는 이점을 얻지는 못합니다 . index = False는 추가 할 때 유용합니다. 예를 들어, 여러 번 추가하면 인덱스를 추가하는 것이 더 효율적입니다. (많은 양의 데이터에 대해) – Jeff

+0

추가를 마치면 인덱스를 어떻게 구성합니까? 판다 문서에 대한 예를 찾을 수 없었습니다. 도와 줘서 고마워. – Michael

관련 문제