수 있다. 새로운 자료구조를 만들지 않고 그 자리에서 바로 축 이름을 변경하는 것이 가능하다.
다음 예제를 살펴보자.
In
[
66
]:
data
=
pd
.
DataFrame
(
np
.
arange
(
12
).
reshape
((
3
,
4
)),
....:
index
=
['
Ohio
',
'
Colorado
',
'
New York
'],
....:
columns
=
['
one
',
'
two
',
'
three
',
'
four
'])
Series
와 마찬가지로 축 색인에도
map
메서드가 있다.
In
[
67
]:
transform
=
lambda x
:
x
[:
4
].
upper
()
In
[
68
]:
data
.
index
.
map
(
transform
)
Out
[
68
]:
Index
(['
OHIO
',
'
COLO
',
'
NEW
'],
dtype
=
'
object
')
대문자로 변경된 축 이름을
DataFrame
의
index
에 바로 대입할 수 있다.
In
[
69
]:
data
.
index
=
data
.
index
.
map
(
transform
)
In
[
70
]:
data
Out
[
70
]:
one two three four
OHIO 0 1 2 3
COLO 4 5 6 7
NEW 8 9 10 11
원래 객체를
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.