Seaborn으로 범주형 플롯 소개

Python으로 범주형 데이터 다루기

Kasey Jones

Research Data Scientist

세 번째 데이터셋

  • 이름: 라스베이거스 TripAdvisor 리뷰 - reviews
  • 행: 504
  • 열: 20
Python으로 범주형 데이터 다루기

라스베이거스 리뷰

reviews.info()
RangeIndex: 504 entries, 0 to 503
Data columns (total 20 columns):
 #   Column             Non-Null Count  Dtype 
     ------             --------------  ----- 
 0   User country       504 non-null    object
...
 6   Traveler type      504 non-null    object
 7   Pool               504 non-null    object
 8   Gym                504 non-null    object
 9   Tennis court       504 non-null    object
...
dtypes: int64(7), object(13)
memory usage: 78.9+ KB
1 https://www.kaggle.com/crawford/las-vegas-tripadvisor-reviews
Python으로 범주형 데이터 다루기

Seaborn

범주형 플롯:

import seaborn as sns
import matplotlib.pyplot as plt

sns.catplot(...)
plt.show()
Python으로 범주형 데이터 다루기

catplot 함수

매개변수:

  • x: data의 변수명
  • y: data의 변수명
  • data: DataFrame
  • kind: 플롯 종류 — 다음 중 하나: "strip", "swarm", "box", "violin", "boxen", "point", "bar", "count"
Python으로 범주형 데이터 다루기

상자 수염 그림

Python으로 범주형 데이터 다루기

리뷰 점수

reviews["Score"].value_counts()
5    227
4    164
3     72
2     30
1     11
Python으로 범주형 데이터 다루기

상자 수염 그림 예시

sns.catplot(
  x="Pool",
  y="Score",
  data=reviews,
  kind="box"
)
plt.show()

Python으로 범주형 데이터 다루기

두 가지 빠른 옵션

# 글꼴 크기와 배경 설정
sns.set(font_scale=1.4)

sns.set_style("whitegrid")
sns.catplot(
  x="Pool",
  y="Score",
  data=reviews,
  kind="box"
)
plt.show()

Python으로 범주형 데이터 다루기

상자 수염 그림 연습

Python으로 범주형 데이터 다루기

Preparing Video For Download...