đĨī¸ Week 08 Lecture
Pandas Workshop: reshaping, pivoting, and merging data
By the end of this lecture, you should be able to: i) stack DataFrames with pd.concat(), ii) reshape wide â long with .melt() for seaborn, iii) reshape long â wide with .pivot_table() including custom aggfunc, iv) connect two DataFrames on a shared key with pd.merge() and check merge quality.
đ Logistics
đLocation: Thursday, 12 March 2026, 4-6 pm at CKK.LG.03
Today is a practical pandas workshop. We will walk through four transformation tools with colour-coded visual examples and live code. If time allows, we will do a group challenge in Hour 2.
đ Preparation
- You went to the đĨī¸ W07 Lecture and đģ W07 Lab
- You completed at least a first version of your
NB01of the âī¸ Mini Project 2.
đŖī¸ Lecture Overview
pd.concat(): stack DataFrames from separate route files (documentation).melt(): reshape wide summary tables to long format (documentation)- That will allow you to use the
hueparameter on seaborn plots more easily (documentation)
- That will allow you to use the
.pivot()and.pivot_table(): to reshape long â wide data (documentation)- The
aggfuncparameter allows you to specify how to aggregate values when pivoting (e.g.mean,sum,count, etc.)
- The
pd.merge(): join your journey data with the ONS Postcode Directory on a postcode key (documentation)
đ Lecture Materials
Today we use facilitation slides plus one lecture notebook. The notebook will be shared on Nuvolos, and you can also download a zip bundle with all Week 08 files used in the notebook.
đŦ Facilitation Slides
Use keyboard arrows to navigate. Select the slides below or view fullscreen.
Or download the slides directly as a PDF:
đĨ Demo Notebook
The demo notebook walks through every transformation shown in the lecture slides, using synthetic TfL-like journey data.
đ Appendix
Useful Links
- âī¸ Mini-Project 2
- đģ W08 Lab
- đ Syllabus
- â Contact Hours
Looking Ahead
- Friday W08 Lab: merge your own TfL data with the ONS Postcode Directory and build
NB02 - Week 09: EDA quality checks and visual communication critique
- Week 10: MP2 submission deadline (Monday 23 March, 8 pm)
