인프런 - 데이터 분석을 위한 판다스 - 섹션 4 - 그룹별 데이터 집계

르네·2023년 10월 13일
0

Python

목록 보기
37/45
본 내용은 인프런 강의 <데이터 분석을 위한 판다스>를 수강하며 중요한 점을 정리한 글입니다.

How to calculate summary statistics
Aggregating statistics

https://pandas.pydata.org/pandas-docs/stable/getting_started/intro_tutorials/06_calculate_statistics.html


그룹별 집계

한 개의 컬럼을 기준 컬럼으로 사용하는 GROUP BY할 경우

titanic.groupby('Sex')['Age'].mean()

->
Sex
female    27.915709
male      30.726645
Name: Age, dtype: float64

여러개의 컬럼을 기준 컬럼으로 사용하는 GROUP BY할 경우

titanic.groupby(['Pclass', 'Sex'])['Fare'].mean()

-> Pclass  Sex   
1       female    106.125798
        male       67.226127
2       female     21.970121
        male       19.741782
3       female     16.118810
        male       12.661633
Name: Fare, dtype: float64
profile
데이터분석 공부로그

0개의 댓글