Chapter 12 · 9 levels
Seaborn, correlation and conclusions
Statistical charts with seaborn (countplot, histplot, boxplot, regplot, heatmap), outliers with the IQR rule, correlation done right, and turning numbers into a written takeaway.
StartThe previous chapter drew charts piece by piece with matplotlib. seaborn is a library built on
top of it for statistical charts: you hand it a DataFrame and column names, and it groups, counts
and colors for you. Every seaborn function follows one pattern, sns.function(data=df, x="col", y="col", hue="col"), and returns a matplotlib Axes, so titles, labels and limits work exactly as
before.
You’ll count with countplot, compare distributions with histplot and boxplot, learn to read a
boxplot properly (median, quartiles, whiskers, outliers) and find outliers with numbers, not by eye.
Then correlation: what the number between -1 and +1 means, how to compute a whole matrix with
corr(), show it as a heatmap, pick the strongest pairs, and why “goes together” never means
“causes”.
The last part is the one that turns analysis into something a manager can use: the takeaway. What did you find, how big is it, and so what? Every number in it computed, not estimated.
How it runs here. seaborn isn’t part of the Python that runs in your browser by default, so the
page loads a pinned copy (and matplotlib) the first time your code says import seaborn as sns.
That takes a few seconds once. As in chapter 11, your charts appear under your result, and the check
looks at the numbers in result.
Levels
- Orders per channel with seaborn
from Robert Kim, Chief Operating Officer
seaborn, countplot, hue, order, value counts
- Business baskets against consumer baskets
from Megan Collins, Head of Sales
seaborn, histplot, hue, kde, distribution, median
- Read the price boxes
from Thomas Whitaker, Head of Merchandising
boxplot, quartiles, iqr, quantile, seaborn
- Which orders are unusually large?
from Laura Bennett, Head of Finance
outliers, iqr, quantile, boxplot, fences
- Does more ad spend bring more visits?
from Jordan Reyes, Head of Marketing
correlation, corr, regplot, scatterplot, pearson r
- The correlation heatmap and the strongest pairs
from Priya Shah, Head of Data
correlation matrix, heatmap, corr, top pairs, abs
- Will doubling ad spend double orders?
from Jordan Reyes, Head of Marketing
correlation, causation, confounder, seasonality
- From numbers to a takeaway
from Megan Collins, Head of Sales
takeaway, conclusions, f strings, percent format, reporting
- Boss: is it the channel or the customer?
from Catherine Hale, Chief Executive Officer
heatmap, pivot table, boxplot, to csv, takeaway