오답노트
[Pandas] Crosstab (교차표) 본문
crosstab
pd.crosstab(col1,col2)
두 범주형 변수로 빈도수를 파악하는데 사용된다.

pd.crosstab(titanic['Survived'], titanic['Sex'])

normalize
normalize 옵션은 빈도 수의 합을 1로 만들어준다.
columns
열의 합이 1이 되도록 normalize 시킨다.
pd.crosstab(titanic['Survived'], titanic['Embarked'], normalize = 'columns')

각 열의 합은 모두 1이다.
index
행의 합이 1이 되도록 normalize 시킨다.
pd.crosstab(titanic['Survived'], titanic['Embarked'], normalize = 'index')

각 행의 합은 1이다.
all
모든 요소의 합이 1이 되도록 normalize 시킨다.
pd.crosstab(titanic['Survived'], titanic['Embarked'], normalize = 'all')

모든 요소를 더하면 1이다.
'Python > Pandas' 카테고리의 다른 글
[Pandas] NaN 처리 (0) | 2022.08.09 |
---|---|
[Pandas] 시간 데이터 (0) | 2022.08.08 |
[Pandas] Rolling 과 Shift (0) | 2022.08.08 |
[Pandas] 데이터 프레임 병합, 붙이기 (0) | 2022.08.08 |
[Pandas] 요소 값 변경 (0) | 2022.08.03 |