2011-10-15 3 views

답변

12

numpy 만 사용하려는 경우 구조적 배열lib.recfunctions.join_by 함수를 사용할 수 있습니다 (http://pyopengl.sourceforge.net/pydoc/numpy.lib.recfunctions.html 참조). 약간의 예 :

In [1]: import numpy as np 
    ...: import numpy.lib.recfunctions as rfn 
    ...: a = np.array([(1, 10.), (2, 20.), (3, 30.)], dtype=[('id', int), ('A', float)]) 
    ...: b = np.array([(2, 200.), (3, 300.), (4, 400.)], dtype=[('id', int), ('B', float)]) 

In [2]: rfn.join_by('id', a, b, jointype='inner', usemask=False) 
Out[2]: 
array([(2, 20.0, 200.0), (3, 30.0, 300.0)], 
     dtype=[('id', '<i4'), ('A', '<f8'), ('B', '<f8')]) 

또 다른 옵션은 팬더를 사용하는 것입니다 (documentation). 나는 경험이 없지만 "관계형"또는 "분류 된"데이터로 쉽고 직관적으로 작업 할 수 있도록 표준 numpy보다 강력한 데이터 구조와 기능을 제공합니다. 그리고 그것은 합류 및 병합 기능을 가지고 있습니다 (예 : http://pandas.sourceforge.net/merging.html#joining-on-a-key 참조).

+0

아,'recfunctions'을 잊어 버렸습니다. 나는 현재 팬더를 평가 중입니다 ... 많은 선택권 ... 고마워요. – hatmatrix