Python

A second language for people who already think in data

20 lessons Beginner to advanced ~40 hours Exercises with solutions

Most people in clinical and statistical programming do not need to choose between R and Python. They need to read both, and reach for whichever suits the task. This course teaches Python from the ground up, with constant reference to the R equivalent — so existing knowledge accelerates rather than interferes.

It then goes further than a language course: producing clinical tables with the pharmaverse rtflite package, and the two areas where Python is the stronger tool — machine learning, and building applications on large language models.

Who this is for

  • R users who need Python for a project, a collaborator or a platform
  • Statistical programmers whose organisation uses Python for data engineering
  • Anyone building ML pipelines, where Python’s ecosystem is much deeper
  • People evaluating what generative AI can and cannot responsibly do in a regulated setting

No Python experience is assumed. Familiarity with R, SAS or any other language will make lessons 1–3 go quickly.

Course outline

Language foundations

# Lesson You will learn
1 Python fundamentals Syntax, types, control flow, f-strings, tracebacks
2 Lists, tuples and dictionaries Collections, comprehensions, mutability
3 Functions and classes Arguments, type hints, decorators, dataclasses

Scientific stack

# Lesson You will learn
4 NumPy Arrays, broadcasting, vectorisation, nan
5 pandas Series and DataFrame, .loc/.iloc, groupby, merge, reshape
6 Data visualization matplotlib, seaborn, plotly, plotnine

Data in and out

# Lesson You will learn
7 File formats and dataset comparison CSV, Excel, JSON, Parquet, HDF5, a PROC COMPARE equivalent
8 Reading SAS and clinical datasets pyreadstat, labels, formats, XPT, encoding
9 Building CDISC datasets in Python SDTM DM end to end, ADSL, specifications, conformant XPT

Analysis and reporting

# Lesson You will learn
10 Statistical analysis Descriptives, t-tests, Fisher, regression, Kaplan-Meier, Cox
11 Machine learning Pipelines, leakage, LR/SVM/trees, neural networks, interpretation
12 Clinical tables and TLF generation Polars, rtflite, submission-quality RTF output

Applications and delivery

# Lesson You will learn
13 Streamlit and Python Shiny Two app frameworks, reactivity, deployment
14 Testing pytest, fixtures, parametrisation, coverage
15 Virtual environments venv, uv, conda, lockfiles, reproducibility
16 Git and deployment pre-commit, packaging, Docker, CI/CD

Generative AI

# Lesson You will learn
17 LLMs and prompt engineering Tokens, sampling, structured output, prompt evaluation
18 Working with LLM APIs Provider APIs, tool calling, retries, cost control, concurrency
19 LangChain and RAG LCEL, chunking, embeddings, hybrid retrieval, evaluation
20 AI agents and MCP Agent loops, LangGraph, MCP servers, guardrails

How to work through it

Lessons 1–3 are the language. If you already program they will go fast — but do not skip lesson 2, because Python’s collections behave differently from R’s vectors in ways that cause real bugs.

Lessons 4–6 are the scientific stack. Lesson 5 (pandas) is the longest and most important; it is where the day-to-day difficulty lives.

Lessons 7–9 are data handling, ending with building a CDISC dataset from raw source. Lesson 9 is honest about the ecosystem gap — there is no admiral for Python, and that lesson shows you exactly what you would be writing yourself.

Lessons 10–12 are analysis and reporting: statistics for inference, machine learning for prediction, then rendering the results as submission-quality RTF with rtflite. The distinction between the first two words is the whole point of lessons 10 and 11.

Lessons 13–16 are about shipping: applications, tests, environments, deployment.

Lessons 17–20 are generative AI, building from prompting up to tool-using agents. They are written for a regulated audience, which means they spend as much time on what these systems should not be used for as on how to build them.

Suggested paths

If you are… Lessons
An R user needing working Python 1–7, then 13–15
Coming from SAS, focused on clinical data 1–5, 7–9
Doing statistical analysis in Python 1–6, 10
Building predictive models 1–6, 10–11
Producing clinical TLFs in Python 1–5, 7–8, 10, 12
Building an internal tool 1–5, 13–16
Evaluating Gen AI for your team 17–20 (skim 1–3 first if new to Python)
Working through everything 1–20 in order
NoteVersions

Examples use Python 3.11+, pandas 2.x, Polars 1.x, NumPy 1.26+, scikit-learn 1.5+, rtflite 1.x, and current releases of Streamlit, Shiny for Python and LangChain. Where pandas 2.0 changed behaviour — copy-on-write, the Arrow backend — the lesson says so.

The generative AI lessons name model identifiers only as illustrations. Model names, pricing and occasionally parameter names change on a timescale of months, so those lessons show you how to read the current documentation rather than encouraging you to trust a literal in a code block.

TipR comparisons throughout

Every lesson has a side-by-side comparison table. The three differences that cause most early mistakes: Python is 0-indexed and R is 1-indexed; Python has scalars and R does not; Python mutates in place where R copies.

Start with Python fundamentals.

Back to top