Seaborn ile kategorik grafiklere giriş

Python'da Kategorik Verilerle Çalışma

Kasey Jones

Research Data Scientist

Üçüncü veri setimiz

  • Ad: Las Vegas TripAdvisor Yorumları - reviews
  • Satır: 504
  • Sütun: 20
Python'da Kategorik Verilerle Çalışma

Las Vegas yorumları

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'da Kategorik Verilerle Çalışma

Seaborn

Kategorik grafikler:

import seaborn as sns
import matplotlib.pyplot as plt

sns.catplot(...)
plt.show()
Python'da Kategorik Verilerle Çalışma

catplot fonksiyonu

Parametreler:

  • x: data içindeki değişken adı
  • y: data içindeki değişken adı
  • data: bir DataFrame
  • kind: grafik türü — şunlardan biri: "strip", "swarm", "box", "violin", "boxen", "point", "bar" veya "count"
Python'da Kategorik Verilerle Çalışma

Kutu grafiği

Python'da Kategorik Verilerle Çalışma

İnceleme puanı

reviews["Score"].value_counts()
5    227
4    164
3     72
2     30
1     11
Python'da Kategorik Verilerle Çalışma

Kutu grafiği örneği

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

Python'da Kategorik Verilerle Çalışma

İki hızlı seçenek

# Yazı tipi boyutu ve arka plan ayarı
sns.set(font_scale=1.4)

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

Python'da Kategorik Verilerle Çalışma

Kutu grafiği alıştırması

Python'da Kategorik Verilerle Çalışma

Preparing Video For Download...