만약 각 로우에 대해 연산을 수행하고 싶다면 산술 연산 메서드를 사용하면 된다. 예를 들어보자.
In
[
186
]:
series3
=
frame
['
d
']
In
[
187
]:
frame
Out
[
187
]:
b d e
Utah 0
.
0 1
.
0 2
.
0
Ohio 3
.
0 4
.
0 5
.
0
Texas 6
.
0 7
.
0 8
.
0
Oregon 9
.
0 10
.
0 11
.
0
In
[
188
]:
series3
Out
[
188
]:
Utah 1
.
0
Ohio 4
.
0
Texas 7
.
0
Oregon 10
.
0
Name
:
d
,
dtype
:
float64
In
[
189
]:
frame
.
sub
(
series3
,
axis
=
'
index
')
Out
[
189
]:
b d e
Utah
-
1
.
0 0
.
0 1
.
0
Ohio
-
1
.
0 0
.
0 1
.
0
Texas
-
1
.
0 0
.
0 1
.
0
Oregon
-
1
.
0 0
.
0 1
.
0
인자로 넘기는
axis
값은 연산을 적용할 축 번호다.
axis
=
'
index
'
나
axis
=
0
은
DataFrame
의
로우를 따라 연산을 수행하라는 의미다.
5.2.6
함수 적용과 매핑
pandas
객체에도
NumPy
의 유니버설 함수(배열의 각 원소에 적용되는 메서드)를 적용할 수
있다.
In
[
190
]:
frame
=
pd
.
DataFrame
(
np
.
random
.
randn
(
4
,
3
),
columns
=
list
('
bde
'),
.....: ...
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.