Introduction to categorical plots using Seaborn

Working with Categorical Data in Python

Kasey Jones

Research Data Scientist

Our third dataset

  • Name: Las Vegas TripAdvisor Reviews - reviews
  • Rows: 504
  • Columns: 20
Working with Categorical Data in Python

Las Vegas reviews

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
Working with Categorical Data in Python

Seaborn

Categorical plots:

import seaborn as sns
import matploblib.pyplot as plt

sns.catplot(...)
plt.show()
Working with Categorical Data in Python

The catplot function

Parameters:

  • x: name of variable in data
  • y: name of variable in data
  • data: a DataFrame
  • kind: type of plot to create - one of: "strip", "swarm", "box", "violin", "boxen", "point", "bar", or "count"
Working with Categorical Data in Python

Box plot

Working with Categorical Data in Python

Review score

reviews["Score"].value_counts()
5    227
4    164
3     72
2     30
1     11
Working with Categorical Data in Python

Box plot example

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

Working with Categorical Data in Python

Two quick options

# 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()

Working with Categorical Data in Python

Boxplot practice

Working with Categorical Data in Python

Preparing Video For Download...