강의

멘토링

커뮤니티

Inflearn Community Q&A

okso64410889's profile image
okso64410889

asked

[Revised Edition] The Complete Guide to Python Machine Learning

Sorting Pandas DataFrame and performing Aggregation function and Group by

집계 함수에서, 동일한 컬럼의 다른 함수 적용

Resolved

Written on

·

255

1

안녕하세요.

1) 동일한 컬럼의 다른 함수 적용

titanic_df.groupby('Pclass')['Age'].agg([max, min])

2) 다른 컬럼에 다른 함수 적용

agg_format = {'Age':'max','SibSp':'sum','Fare':'mean'}

titanic_df.groupby('Pclass').agg(agg_format)

Q. 1) 2) 두가지를 동시에 할 순 없나요?

agg_format = {'Age':'max'   ,'Age':'min'   ,'SibSp':'sum','Fare':'mean'}

titanic_df.groupby('Pclass').agg(agg_format)

SELECT MAX(Age), MIN(Age), SUM(SibSp), AVG(Fare)

  FROM TITANIC_DF

 GROUP BY Pclass

처럼요. Q 결과에서는 Age 가 뒤에 위치한 Min 값으로 표현되서 Age|SibSp|Fare 세가지 컬럼만 나옵니다.

감사합니다.

python통계머신러닝 배워볼래요?

Answer 2

1

dooleyz3525님의 프로필 이미지
dooleyz3525
Instructor

안녕하십니까,

가능합니다. 'Age':['max', 'min'] 처럼 리스트로 aggregation 함수들을 선언해 주면 됩니다.

agg_format={'Age':['max','min'], 'SibSp':'sum', 'Fare':'mean'}
titanic_df.groupby('Pclass').agg(agg_format)

감사합니다.

0

okso64410889님의 프로필 이미지
okso64410889
Questioner

감사합니다!!!!

okso64410889's profile image
okso64410889

asked

Ask a question