[AI 기초] pandas DataFrame

clean·2023년 8월 30일
0

이 글은 계속 업데이트됩니다

데이터프레임 정렬

dataframe, series의 정렬은 sort_values()를 이용해서 한다.
by(정렬기준), ascending, inplace 등의 옵션을 줄 수가 있다.

#예시
titanic_sorted = titanic_df.sort_values(by=['Pclass', 'Name'], ascending=False)

Aggregation 함수

데이터프레임에는 min(), max, sum(), count()와 같은 aggregation 함수를 적용할 수 있다.

titanic_df.count()

이렇게 치면 colum 별로의 count가 나오는 것을 확인할 수 있다.

titanic_df[['Age', 'Fare']].mean()

위와 같이 특정 colum에만 aggregation 함수를 쓸 수도 있다.

groupby 함수

데이터프레임에 groupby()를 호출하면 DataFrameGroupBy라는 또 다른 형태의 데이터프레임을 반환한다.
이 반환된 결과에 aggregation 함수를 호출하면 groupby() 대상 칼럼을 제외한 모든 칼럼에 aggregation 함수를 적용한다.

titanic_groupby = titanic_df.groupby(by='Plcass').count()
titanic_groupby
profile
블로그 이전하려고 합니다! 👉 https://onfonf.tistory.com 🍀

0개의 댓글