Chapter 1 of Foundations
Scientific Python for data work
The tools every later chapter assumes: NumPy arrays for fast numerical work, pandas DataFrames for tables of measurements, and matplotlib and seaborn for figures you can trust. You will practise on real data, from Antarctic penguins to a medical imaging dataset, and finish with a full exploratory analysis of the aqueous solubility of small molecules, the question Chapter 2 then tries to predict.
What you will be able to do
- Write short, readable Python for scientific data: lists and dictionaries as lookup tables, functions with docstrings, f-strings for formatted output,
pathlibfor files, and tracebacks read from the bottom up. - Store measurements in NumPy arrays, select them with slices and boolean masks, replace loops with vectorised arithmetic and broadcasting, and generate reproducible random numbers with a seeded generator.
- Recognise the \(X\) (samples × features) / \(y\) (targets) convention that every model in this course consumes.
- Load, inspect, filter, group, merge and reshape tables with pandas, and handle missing values and categorical columns deliberately rather than by accident.
- Draw histograms, scatter plots, box plots and small multiples with matplotlib and seaborn, with units on every axis and colours that work for everyone.
- Carry out an exploratory data analysis of the ESOL solubility dataset end to end, and repeat the workflow on the breast cancer Wisconsin dataset in the guided lab.
Schedule
| Episode | Cumulative time | Questions |
|---|---|---|
|
1.1Python refresher for scientists 25 min teaching + 15 min exercises |
40 min |
|
|
1.2NumPy arrays 35 min teaching + 20 min exercises |
1 h 35 min |
|
|
1.3pandas DataFrames 40 min teaching + 25 min exercises |
2 h 40 min |
|
|
1.4Visualising data with matplotlib and seaborn 30 min teaching + 20 min exercises |
3 h 30 min |
|
|
1.5EDA case study: aqueous solubility 35 min teaching + 20 min exercises |
4 h 25 min |
|
|
Lab 1Guided EDA: the breast cancer Wisconsin dataset 60–90 min |
5 h 40 min | Run the EDA checklist from episode 1.5 on the breast cancer Wisconsin dataset, from shape and class balance to a feature ranking and a written summary, with checks after every task. |
Lab
Lab 1, 60–90 min
Guided EDA: the breast cancer Wisconsin dataset
Run the EDA checklist from episode 1.5 on the breast cancer Wisconsin dataset, from shape and class balance to a feature ranking and a written summary, with checks after every task.
Dataset: Breast cancer Wisconsin (diagnostic), via scikit-learn; no download needed
Before you start
You need a working Python environment and the habit of running code in a notebook. If you have not done so, work through Chapter 0 and make sure you pass its self-check: it confirms that NumPy, pandas, matplotlib and scikit-learn import correctly and that data/penguins.csv is where this chapter expects it.
If you already write Python for a living, skim episode 1.1 for the scientific examples and the pathlib and f-string conventions this course uses, then start properly at episode 1.2. NumPy’s broadcasting rules and pandas’ label-based indexing are where experienced programmers most often trip, so slow down there.