여기서는 새로운 column('PURPOSE')를 생성하기 위해 사용했다.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
conditionlist = [
(credit_df['NEW_CAR'] == 1),
(credit_df['USED_CAR'] == 1),
(credit_df['FURNITURE'] == 1),
(credit_df['RADIO/TV'] == 1),
(credit_df['EDUCATION'] == 1),
(credit_df['RETRAINING'] == 1)]
choicelist = ['New Car', 'Used Car', 'Furniture', 'Radio/TV', 'Education', 'Retraining']
credit_df['PURPOSE'] = np.select(conditionlist, choicelist, default='Other')
credit_df.drop(['NEW_CAR', 'USED_CAR', 'FURNITURE', 'RADIO/TV', 'EDUCATION', 'RETRAINING'], axis=1, inplace=True)
credit_df.head()
|
cs |
아래는 파라미터 설명
1. numpy.select(condlist, choicelist, default=0)
조건에 따라 선택 목록의 요소에서 가져온 배열을 반환.
2. Parameterscondlistlist of bool ndarrays
선택 목록의 어떤 배열에서 출력 요소를 가져 choicelist 를 결정하는 조건 목록. 여러 조건이 충족되면 condlist 에서 처음 발견된 조건 이 사용.
3. choicelistlist of ndarrays
출력 요소를 가져오는 배열 목록. condlist 와 길이가 같아야 함.
4. defaultscalar, optional
모든 조건이 False로 평가될 때 output 삽입된 요소.
5. Returnsoutputndarray
위치 m의 출력은 choicelist 에 있는 배열 의 m 번째 요소, condlist 에 있는 해당 배열의 m 번째 요소는 True.
'배운 것 > Python' 카테고리의 다른 글
| [pandas] 기존 데이터 프레임에서 열(column)을 삭제한 후, 새로운 데이터 프레임으로 저장하기 (0) | 2021.09.14 |
|---|---|
| [pandas] DataFrame loc[ ] 연산자 - Index(인덱스) (0) | 2021.07.20 |
| [pandas] get_dummies : One-hot encoding(원핫 인코딩) (0) | 2021.07.20 |
| [기초 문법] dict()로 딕셔너리 만들기 (0) | 2021.03.31 |
| [기초 문법] input().split() (0) | 2021.03.31 |