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.
Open the lab, then use its Open in Colab button.
Data: qahwa
_orders _2025 .csv (10,200 receipts from 2025, one row per order). The notebook downloads it by itself. Submit the notebook and your
qahwa_app.pybefore the next lab session. The solutions are for checking your work afterwards.
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:
GitHub Codespaces (free with GitHub Education) or your own computer: open a terminal in the folder with the app, run
pip install streamlit pandas, thenstreamlit run qahwa_app.py. A browser tab opens athttp://localhost:8501.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.