seaborn and interactive charts · lesson 10 of 10
Parts in this lesson
Asns.displot(..., col="store", col_wrap=2)7.2, 7.6: a distribution per store
Bsns.boxplot(...) + sns.stripplot(..., ax=ax)7.3: a summary with every day behind it
Csns.pairplot(items, hue="store")7.5: every pair, coloured by store
Dpx.line(..., hover_data=...).write_html(...)7.8: a chart the owners can explore

Project: a Tindahan exploration notebook

Last updated

Project 6.P answered six questions the owners asked. This one asks what else the data says. You'll explore the clean Tindahan data the seaborn way: how each store's takings are spread, how the stores compare across the week, what rain does to sales, and how the items move together. Then you'll make two interactive Plotly charts the owners can explore themselves, and write down what you found.

By the end of this lesson you can

  • Explore a dataset with distribution, comparison and relationship charts in seaborn
  • Check a finding group by group before believing it
  • Make interactive charts for readers to explore, and save them as web pages
  • Write short notes that say what the charts show, with numbers

Plan it

The clean files from project 5.P are in data/clean/: sales, stores, products and weather, for January and February 2024. In 6.P you drew answers to questions the owners chose. Exploring works the other way round: you look at the data from several sides to find out what questions are worth asking. The charts are for you first; only the clearest go to the owners.

StepLooking forCharts
2how each store's daily takings are spreadhistograms in panels, ECDFs (7.2, 7.6)
3how stores compare, overall and by weekdaybox plots with points, a point plot (7.3)
4what rain does to sales, store by storebox plots by rainy and dry, fitted lines (7.4)
5how the items and rain move togethera pair plot and correlations (7.5)
6charts the owners can exploretwo Plotly charts, saved as HTML (7.8)
7what you foundnotes, with numbers

Every notebook starts with the same setup cell. It loads the four files, works out pesos for each sale, and makes day: one row per store per day (240 rows), with kilos, pesos, the rain in that store's town, the weekday, and rainy, which is True when any rain fell. It also sets one theme for every chart, whitegrid with the colour-blind palette (7.1), and the store order used throughout: biggest first.

How takings are spread

Run the cells.

07-explore.ipynb
  • The histograms, one per store on shared axes, show each store's days spread around its own level, with a tail of busy days to the right. Batangas sits furthest right and is the most spread out.
  • The ECDFs put the four stores on one chart. They don't cross: whatever share of days you pick, the stores come in the same order. Reading across at 0.5 gives each store's median day.
  • The table gives the numbers: a median day of ₱3,031 at Batangas, ₱2,284 at Lipa, ₱1,955 at Tanauan and ₱1,533 at Rosario. Rosario's best day, ₱2,264, is below Batangas' worst, ₱2,400.

In each store the mean is a little above the median: that's the tail of busy days pulling it up.

Store comparisons

Run the cells.

07-explore.ipynb
  • Box plots with every day on top (7.3): fliersize=0 turns off the box plot's own outlier dots, since the strip plot already draws every day.
  • The point plot by weekday shows the same weekly shape at every store: lowest on Tuesday, highest on Saturday. Batangas takes in ₱4,124 on an average Saturday and ₱2,752 on an average Tuesday, half as much again.
  • The shares: Batangas brings in 34.7% of all the money, Lipa 25.7%, Tanauan 22.3% and Rosario 17.3%.

Because the lines in the point plot run almost parallel, the weekday pattern is the same everywhere: it's about when customers shop, not about any one store.

Weather against sales

Project 6.P found that rainy days sell a little less, with all stores together. Check it store by store. Run the cells.

07-explore.ipynb
  • hue="rainy" splits each store's box into dry and rainy days.
  • The table compares the mean kilos: rainy days sell 11.9% less at Batangas, 16.8% less at Lipa, 12.2% less at Tanauan and 11.9% less at Rosario. Every store, not just the total, so this isn't Simpson's paradox (7.4) at work.
  • The fitted lines use rainy days only, about 17 to 20 per store, to ask whether more rain means fewer sales. The lines are rough, with few days behind each, so treat them as a hint. Stage 8 shows how to say how sure a difference like this is.

A pair plot

Do the three items sell together? Run the cells: a table with one row per store-day and a column per item, plus rain.

07-explore.ipynb

The correlations between rice, sugar and oil are all 0.93. That looks like a strong finding until you look at the pair plot's colours: each store is its own cloud, and the clouds line up from Rosario to Batangas. Most of the 0.93 is just that big stores sell more of everything. Inside one store's cloud the points are much more spread out.

It's the lesson from 7.4 again: with groups in the data, look inside each group before trusting the overall number. Rain's correlations with the items are small and negative (−0.14 to −0.19), matching step 4.

Two Plotly charts

The owners don't run Python, so give them charts they can explore in a browser. Run the cells, then try the charts: hover, zoom, and click a store in the legend.

07-explore.ipynb
  • The line chart of daily takings has a line per store; hovering shows the day's kilos (to one decimal, with ":.1f"), the rain and the weekday, so an owner can check a strange day themselves. Clicking a store in the legend hides it.
  • The scatter plot of rain against kilos has a panel per store (facet_col="store"), with the date and weekday on hover, so the owners can find the rainy days that still sold well.
  • write_html(..., include_plotlyjs="cdn") saves each as a small web page in reports/. (For owners who may be offline, leave out include_plotlyjs to put plotly.js inside the file.)

Notes on what you found

Exploring is only finished when it's written down. Add a Markdown cell at the end of your notebook (on your computer, 07-explore.ipynb) with a few short notes, each with its numbers and the chart it came from. For example:

  1. Every store has the same week. Saturday is the busiest day and Tuesday the quietest, at all four stores. Batangas' average Saturday brings in ₱4,124, against ₱2,752 on a Tuesday. (Point plot, step 3.)
  2. Batangas is a third of the business. 34.7% of the money; Rosario's best day is below Batangas' worst. (Table and ECDFs, steps 2 and 3.)
  3. Rain costs sales everywhere. Rainy days sold 12% to 17% fewer kilos than dry days at every store, most at Lipa. (Step 4.)
  4. Items don't tell us much yet. The 0.93 correlations between items come from store size. To know whether, say, sugar sells with rice on the same visit, we'd need receipts, not daily totals. (Pair plot, step 5.)

Notice the last note: a good exploration also says what the data can't answer, and what would answer it.

Finished

Run the notebook in step 6 again from the top: it should list rain.html and takings.html.

Look at what you used:

  • seaborn from tidy data (7.1): one table, day, and columns named for each chart, with one theme throughout.
  • Distributions (7.2): histograms in panels and ECDFs.
  • Group comparisons (7.3): box plots with every point, a point plot.
  • Relationships, checked by group (7.4, 7.5): rainy against dry in every store, and a pair plot whose colours explained a correlation.
  • Facets (7.6): a panel per store, in order of size.
  • Interactive charts (7.8): hover details, a legend that filters, and HTML files to share.

In Stage 8 you'll put numbers on how sure these findings are: is a 12% drop on rainy days real, or could 18 rainy days give that by chance?

Sources

Every example on this page was run with Python 3.14, and its output and error messages are copied from it. These pages cover the same ground in more depth.

All sources for Simple Data Analysis