Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

4. Relationships in Data

How two variables relate: crosstabs and pivot tables, box plots across groups, scatterplots and correlation, and the two traps behind a relationship (confounding and Simpson’s paradox). Then a first Streamlit app that puts the analysis in the manager’s hands.

Slides

Present full screen Download the PDF

Click or tap the slide to move forward, its left edge to go back; the arrow keys work too.

Reading

Relationships in Data works through every tool of the lecture on Qahwa House’s receipts: which branch app users favour, food sales by branch, why Iced Latte and Spanish Latte correlate positively day by day but negatively month by month, and how app users can spend more in every branch yet less overall.

Lab 4: Relationships and a first Streamlit app

The regional manager wants one dashboard to explore the orders, and one answer: which branch and category combination is underperforming, and what should be done about it? You analyse the receipts with crosstabs, pivot tables and correlations, then write a Streamlit app with filters, a pivot table, a chart and a correlation view, and test it inside the notebook.

Running the app

Colab cannot display a Streamlit page, so the lab tests the app with Streamlit’s AppTest. To see it in a browser:

  1. GitHub Codespaces (free with GitHub Education) or your own computer: open a terminal in the folder with the app, run pip install streamlit pandas, then streamlit run qahwa_app.py. A browser tab opens at http://localhost:8501.

  2. Share it: push the app to a GitHub repository and deploy it on Streamlit Community Cloud, choosing the repository and the file. You get a public link.

The finished course version, with headline numbers, a Simpson’s paradox alert and more views: app.py and its requirements.txt. In a clone of the course repository, run it with streamlit run week04/app/app.py.

Next week

Probability for decisions: the normal, binomial and Poisson models, sampling, and confidence intervals.

→ Week 5: Probability for Decisions