Introducere în graficele categorice cu Seaborn

Lucrul cu date categoriale în Python

Kasey Jones

Research Data Scientist

Al treilea set de date

  • Nume: Recenzii TripAdvisor Las Vegas - reviews
  • Rânduri: 504
  • Coloane: 20
Lucrul cu date categoriale în Python

Recenzii Las Vegas

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
Lucrul cu date categoriale în Python

Seaborn

Grafice categorice:

import seaborn as sns
import matplotlib.pyplot as plt

sns.catplot(...)
plt.show()
Lucrul cu date categoriale în Python

Funcția catplot

Parametri:

  • x: numele variabilei din data
  • y: numele variabilei din data
  • data: un DataFrame
  • kind: tipul graficului - unul dintre: "strip", "swarm", "box", "violin", "boxen", "point", "bar" sau "count"
Lucrul cu date categoriale în Python

Box plot

Lucrul cu date categoriale în Python

Scorul recenziei

reviews["Score"].value_counts()
5    227
4    164
3     72
2     30
1     11
Lucrul cu date categoriale în Python

Exemplu de box plot

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

Lucrul cu date categoriale în Python

Două opțiuni rapide

# Setting font size and plot background
sns.set(font_scale=1.4)

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

Lucrul cu date categoriale în Python

Exersați box plot

Lucrul cu date categoriale în Python

Preparing Video For Download...