반응형
[Python & Matplotlib] 타이타닉 생존자 데이터를 활용한 데이터 시각화 그리기 !!
타이타닉 생존자 데이터를 활용하여 아래와 같은 3가지의 데이터 탐색 및 시각화를 하였습니다.
- 생존자 수 카운트
- 성별에 따른 생존자 수
- 클래스별 생존자 수
예제코드
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# Seaborn 내장 타이타닉 데이터셋 로드
titanic = sns.load_dataset('titanic')
# 그래프 그리기 설정
fig, axes = plt.subplots(1, 3, figsize=(18, 5))
# 전체 생존자 수
sns.countplot(x='survived', data=titanic, ax=axes[0])
axes[0].set_title('Total Survival Counts')
axes[0].set_xticklabels(['Deceased (0)', 'Survived (1)'])
# 성별에 따른 생존자 수
sns.countplot(x='survived', hue='sex', data=titanic, ax=axes[1])
axes[1].set_title('Survival Counts by Gender')
axes[1].set_xticklabels(['Deceased (0)', 'Survived (1)'])
# 클래스별 생존자 수
sns.countplot(x='survived', hue='class', data=titanic, ax=axes[2])
axes[2].set_title('Survival Counts by Ticket Class')
axes[2].set_xticklabels(['Deceased (0)', 'Survived (1)'])
plt.tight_layout()
plt.show()
결과
728x90
반응형
'Coding > 데이터 시각화' 카테고리의 다른 글
[Python & Matplotlib] 명사 추출 후 그래프로 시각화하는 방법 !! (0) | 2024.11.27 |
---|---|
[Python & Matplotlib] seaborn 'tips' 데이터셋을 활용하여 산점도 그래프 그리기 !! (0) | 2024.03.03 |
[Python & Matplotlib] 아이리스(iris) 붓꽃 데이터셋을 활용하여 산점도 그래프 그리기 !! (0) | 2024.02.29 |
[Python & Matplotlib] Matplotlib라이브러리를 활용한 산점도 그래프 그리기 !! (0) | 2024.02.28 |
댓글