Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Python Functions Lab

Functions are one of the most powerful tools in Python. They let you write a piece of logic once and reuse it across different inputs, eliminating the need to copy and paste the same code block every time your data changes. This is the foundation of automation in data work.

It also turns out you have been using functions all along. The libraries at the center of this course, i.e., pandas, geopandas, shapely, are fundamentally just large, carefully organized collections of pre-written functions and classes. Their closest cousins are methods: the commands you attach directly to your data using dot notation, like df.head() or gdf.plot(). Same idea, slightly different form.

This lab builds your mental model from the ground up: what a function is made of, how Python executes it, and how to write one correctly.

What you will practice:

The lab has seven activities across four modes — Assemble, Fill the Gaps, Matching, and a Try It REPL at the bottom of every coding exercise that runs your assembled function directly in the browser. No install required.


Activities at a glance:

#ModeFunctionWhat you practice
1Assemblegreet(name: str)Order and indent a 3-line function
2Matchinggreet()Name every structural part of a function
3Assembleclean_column_names(df)Chain .str accessor methods to vectorize column name cleaning
4Assemblecelsius_to_f(c: float)Arithmetic expression, single return
5Fill the Gapsabsolute_value(n: float)Conditional with early return
6Fill the Gapsclassify_grade(score: int)if / elif / else chain; type hints in signatures
7Matchingclassify_grade()Name conditional structure: branch, elif, comparison operator

© 2026 Maryam Hosseini