Working With Categorical Data Chapter3
Working With Categorical Data Chapter3
categorical plots
using Seaborn
W O R K I N G W I T H C AT E G O R I C A L D ATA I N P Y T H O N
Kasey Jones
Research Data Scientist
Our third dataset
Name: Las Vegas TripAdvisor Reviews - reviews
Rows: 504
Columns: 20
1 https://www.kaggle.com/crawford/las-vegas-tripadvisor-reviews
Categorical plots:
sns.catplot(...)
plt.show()
data : a DataFrame
kind : type of plot to create - one of: "strip" , "swarm" , "box" , "violin" , "boxen" ,
"point" , "bar" , or "count"
5 227
4 164
3 72
2 30
1 11
sns.catplot(
x="Pool",
y="Score",
data=reviews,
kind="box"
)
plt.show()
Kasey Jones
Research Data Scientist
Traditional bar chart
# Code provided for clarity
reviews["Traveler type"].value_counts().plot.bar()
sns.set(font_scale=1.2)
sns.set_style("darkgrid")
sns.catplot(x="Traveler type", y="Score", data=reviews, kind="bar",
hue="Tennis court") # <--- new parameter
Kasey Jones
Research Data Scientist
Point plot example
sns.catplot(x="Pool", y="Score", data=reviews, kind="point") # <--- updated
Kasey Jones
Research Data Scientist
Difficulties with categorical plots
x : "Traveler type"
kind : "count"
col_wrap : 3
palette : sns.color_palette("Set1")