이라고도 함)해야 하는 경우가 생긴다. 이를 위해 각각의 구별되는 카테고리를 컬럼으로 가지는
DataFrame
을 생성하는데, 각 컬럼에는 해당 카테고리 여부에 따라
0
과
1
의 값을 가지게 된다.
앞서 살펴본 예제를 다시 살펴보자.
In
[
73
]:
cat
_
s
=
pd
.
Series
(['
a
',
'
b
',
'
c
',
'
d
']
*
2
,
dtype
=
'
category
')
7
장에서 다루었듯이
pandas
.
get
_
dummies
함수는 이런
1
차원 범주형 데이터를 더미값을 가지
는
DataFrame
으로 변환한다.
In
[
74
]:
pd
.
get
_
dummies
(
cat
_
s
)
Out
[
74
]:
a b c d
0 1 0 0 0
1 0 1 0 0
2 0 0 1 0
3 0 0 0 1
4 1 0 0 0
5 0 1 0 0
6 0 0 1 0
7 0 0 0 1
12.2
고급
GroupBy
사용
10
장에서
Series
와
DataFrame ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.