2016-08-30 3 views
0

나는 팬더 데이터 프레임을 색인과 함께 부울 값의 사각형 격자로 만들고이 열이 이웃을 가진 628 개의 선거 구민의 이름으로 만듭니다. 예 :팬더에서 기준과 일치하는 열 이름 반환하기

In[18]: adjacents.index 
Out[18]: 
Index(['Aberavon', 'Aberconwy', 'Aberdeen North', 'Aberdeen South', 
     'Aberdeenshire West & Kincardine', 'Airdrie & Shotts', 'Aldershot', 
     'Aldridge-Brownhills', 'Altrincham & Sale West', 'Alyn & Deeside', 
     ... 
     'Wrekin, The', 'Wrexham', 'Wycombe', 'Wyre & Preston North', 
     'Wyre Forest', 'Wythenshawe & Sale East', 'Yeovil', 'York Central', 
     'York Outer', 'Yorkshire East'], 
     dtype='object', length=628) 

In[19]: adjacents.columns 
Out[19]: 
Index(['Aberavon', 'Aberconwy', 'Aberdeen North', 'Aberdeen South', 
     'Aberdeenshire West & Kincardine', 'Airdrie & Shotts', 'Aldershot', 
     'Aldridge-Brownhills', 'Altrincham & Sale West', 'Alyn & Deeside', 
     ... 
     'Wrekin, The', 'Wrexham', 'Wycombe', 'Wyre & Preston North', 
     'Wyre Forest', 'Wythenshawe & Sale East', 'Yeovil', 'York Central', 
     'York Outer', 'Yorkshire East'], 
     dtype='object', length=628) 

맨체스터 센트럴 구성은 맨체스터 고튼 (Manchester Gorton)과 인접하지만 맨체스터 위 핑턴 (Manchester Withington)과 인접하지 않습니다.

In[20]: adjacents['Manchester Central']['Manchester Withington'] 
Out[20]: False 

In[21]: adjacents['Manchester Central']['Manchester Gorton'] 
Out[21]: True 

True입니다 행의 모든 ​​열에 대한 열 이름을 반환하는 가장 좋은 방법은 무엇입니까? (나는 np.argmax() 함께 할 수있는 뭔가가 될 수도 있지만 확실히 그것을 알아낼 수 있다고 생각합니다.)

답변

1

글쎄, 당신 할 당신의 행렬 symmetric 것 같다 있기 때문에,하지만 당신은을 찾는 더 나을 거라고 이 훨씬 간단하기 때문에 행 이름 대신 : BTW

adjacents[adjacents['Manchester Central']].index 

- 테이블에 정확한 위치를 액세스 할 때, 그것을 사용하는 것이 더 좋습니다 loc :

adjacents.loc['Manchester Central', 'Manchester Gorton'] 
관련 문제