여기 DataFrame 주어진 칼럼 내의 특정 그룹에 대응하는 인덱스를 반환 최소한 약간 견고한 함수의 중 :
# create some data
d = pd.DataFrame({'sex': ['male', 'male', 'female', 'male', 'female', 'female', 'male'], 'age': [23, 24, 20, 32, 45, 43, 32]})
# returns a dictionary with group names as keys and indices corresponding
# to those groups as values (can just use `list` or `set` to avoid pandas indexes
def get_indices(df, col):
return {group: df[df[col] == group].index for group in set(df[col])}
# test it out
get_indices(d, 'sex')
Out[178]:
{'female': Int64Index([2, 4, 5], dtype='int64'),
'male': Int64Index([0, 1, 3, 6], dtype='int64')}
은
을 고려 – EdChum