본 내용은 인프런 강의 <데이터 분석을 위한 판다스>를 수강하며 중요한 점을 정리한 글입니다.
How to calculate summary statistics
Aggregating statistics
How to calculate summary statistics
Aggregating statistics
titanic['Pclass'].value_counts()
->
3 491
1 216
2 184
Name: Pclass, dtype: int64
Both size and count can be used in combination with groupby. Whereas size includes NaN values and just provides the number of rows (size of the table), count excludes the missing values. In the value_counts method, use the dropna argument to include or exclude the NaN values.
titanic.groupby('Pclass')['Age'].count()
->
Pclass
1 186
2 173
3 355
: COUNT()는 NULL값은 세주지 않음.
titanic.groupby('Pclass')['Age'].size()
->
Pclass
1 216
2 184
3 491
: size()는 NULL값도 세준다.
titanic['Age'].value_counts().sum()
->
714
: NULL 값 빼고 세어주는 경우
titanic['Age'].value_counts(dropna=False).sum()
-> 891
: NULL 값 포함해서 세어주는 경우