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.
| Step | Looking for | Charts |
|---|---|---|
| 2 | how each store's daily takings are spread | histograms in panels, ECDFs (7.2, 7.6) |
| 3 | how stores compare, overall and by weekday | box plots with points, a point plot (7.3) |
| 4 | what rain does to sales, store by store | box plots by rainy and dry, fitted lines (7.4) |
| 5 | how the items and rain move together | a pair plot and correlations (7.5) |
| 6 | charts the owners can explore | two Plotly charts, saved as HTML (7.8) |
| 7 | what you found | notes, 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.
- 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.
- Box plots with every day on top (7.3):
fliersize=0turns 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.
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.
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.
- 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 inreports/. (For owners who may be offline, leave outinclude_plotlyjsto 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:
- 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.)
- 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.)
- Rain costs sales everywhere. Rainy days sold 12% to 17% fewer kilos than dry days at every store, most at Lipa. (Step 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.
- seaborn: An introduction to seaborn: the functions this project uses, side by side
- Tukey, Exploratory Data Analysis, Addison-Wesley, 1977 (as discussed in Brillinger, John W. Tukey: His Life and Professional Contributions, Annals of Statistics 30(6), 2002): looking at data to find questions, before testing answers
- Plotly: Line Charts in Python: px.line, colour by group, and hover data