인코더(Encorder) - pd.get_dummies

get_dummies

  • OneHotEncoder와 동일하며 편한 방법으로 사용하면 됩니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 예시 데이터
df = pd.DataFrame({'C1': np.random.randn(20),'C2': ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a','b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b']})
C1 C2
0 0.839674 a
1 -0.514992 a
2 -2.072183 a
3 -1.664719 a
4 0.881287 a
5 -1.151537 a
6 0.768122 a
7 0.942399 a
8 0.384411 a
9 -1.072716 a
10 0.216321 b
11 -0.018060 b
12 -0.297903 b
13 1.430495 b
14 -0.258497 b
15 0.509483 b
16 0.526239 b
17 1.305845 b
18 -0.900900 b
19 -0.463382 b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# C2열 더미화
pd.get_dummies(df,columns=['C2'],prefix='word')

C1 word_a word_b
0 0.303355 1 0
1 0.320274 1 0
2 -1.192643 1 0
3 -0.582344 1 0
4 1.233197 1 0
5 0.053738 1 0
6 -0.761975 1 0
7 -0.702154 1 0
8 0.949892 1 0
9 1.346181 1 0
10 1.883862 0 1
11 -0.766519 0 1
12 -0.417308 0 1
13 -0.674398 0 1
14 0.589356 0 1
15 -1.489583 0 1
16 0.077735 0 1
17 0.479897 0 1
18 1.244302 0 1
19 -2.331532 0 1
Author

InhwanCho

Posted on

2022-11-21

Updated on

2022-11-21

Licensed under

Comments