Skip to content
Learn Python with BNHR

Course · Intermediate · 20–24 hours

About Python for Survey Statistics

Take a household survey from its regional databases to published tables in Python: match keys, write edit rules, tabulate with design-based estimates in svy, and publish to Excel; then find anomalies with rules, scikit-learn and PyOD, with a showcase of AI agents, hosted and local, as a stretch. Taught in marimo on a survey of fishing households invented for the course, for learners who have finished Arrays & DataFrames.

Code SVYLevel IntermediateLength 20–24 hoursModules 9Extras 10
On this page
  1. Overview
  2. The modules
  3. When you are stuck
  4. Certification and support

Take a survey from its regional databases to published tables, then find what is wrong in it.

You work in marimo notebooks with pandas, polars and DuckDB on a survey of fishing households kept the way survey data often is: one database per region. You read every region in one query, match the keys between tables, write edit rules as data, recode and tabulate, estimate under the survey design with svy, and publish to Excel from a script you can run again. Then you find anomalies two ways: with rules and statistics, and with machine learning in scikit-learn and PyOD. An optional stretch closes the course with a showcase of what AI agents, hosted or on your own machine, can do for this pipeline, and how to keep your data safe when you use them.

The course follows Arrays & DataFrames: you need what it covers (pandas and polars, reading files with the right types, groupby, joins, survey weights). Python for Data Management is recommended, since modules 2 and 4 build on its database work and pipelines. If you come from R, primer P1 sets each verb you know beside its Python; if survey sampling is new to you, primer P2 explains it on one page.

The data is the Survey of Fishing Households 2025, a survey invented for this course: its tables, variable names, sampling design, households, fishing units, catch, weights and interviewers are made up for teaching. Its places are real: the region, province and city or municipality codes and names are the PSGC’s, 3rd quarter 2026.

Each module is one topic, taught in sections; a training groups them into its own days or sessions.

  1. Module 1, Start here
  2. Module 2, Get the tables: from regional databases to one flat table
  3. Module 3, Match the keys
  4. Module 4, Edit rules and duplicates
  5. Debugging drill D1, Debugging drill: a flat table that lies
  6. Stretch exercises S1, Stretch: processing
  7. Module 5, Recode and tabulate
  8. Module 6, Estimate under the survey design
  9. Module 7, Publish the tables
  10. Stretch exercises S2, Stretch: tabulation
  11. Module 8, Anomalies by rule and by statistics
  12. Module 9, Anomalies with machine learning
  13. Debugging drill D2, Debugging drill: a detector that flags the wrong rows
  14. Stretch exercises S3, Stretch: detection
  15. Stretch exercises S4, Stretch: agents for your pipeline, a showcase
  16. Capstone

For any time

Every exercise has a check that names the input that went wrong, and a note of common causes. If you are still stuck after ten minutes, or your check is green and you want to compare, the companion has the solution to each exercise and why it works.

Certification and support

We offer additional resources, certificates, ongoing support, and other perks to those who join our instructor-led training.

Join an upcoming training to take this as an instructor-led course, or contact us to arrange one for your team or organization.

Something new

Identify results
LayerExplore a module
ModuleEdit rules and duplicates
AboutModule 4 of Python for Survey Statistics: editing and cleaning a survey's data: frequency tables against the codebook, cross-item rules, specifications that edit with a log, and duplicates by key and by a stated definition. Its sections, its notebooks to read on the web, and the companion's solutions and explanations.
CoursePython for Survey Statistics, free