특히 대용량 데이터를 다룰 경우 소수의 컬럼만 집계하고 싶을 때가 종종 있는데, 예를 들어 위
데이터에서
data2
컬럼에 대해서만 평균을 구하고 결과를
DataFrame
으로 받고 싶다면 아래
와 같이 작성한다.
In
[
31
]:
df
.
groupby
(['
key1
',
'
key2
'])[['
data2
']].
mean
()
Out
[
31
]:
data2
key1 key2
a one 1
.
319920
two 0
.
092908
b one 0
.
281746
two 0
.
769023
색인으로 얻은 객체는
groupby
메서드에 리스트나 배열을 넘겼을 경우
DataFrameGroupBy
객체가 되고, 단일 값으로 하나의 컬럼 ...
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.