# A Cleaning Function, Step by Step

Cleaning steps scattered across notebook cells are hard to run again the same way, so each step becomes a function that starts with result = df.copy() and returns a new table, one clean(raw) function runs them all in order, method chaining with pipe, assign and rename writes it as one readable recipe, and in pandas 3 a single value is changed with .loc.

![Cheat sheet: A Cleaning Function, Step by Step](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/72d106b1c9104fbcaa6d64beb3a422b2.webp)

- Category: Data Analysis
- Level: Journeyman
- Tags: assign(), Copy-on-Write, Lambda Function, Method Chaining (python), pipe, python
- Author: Gregor Dzierzon
- Updated: November 23, 2026

Source: https://www.ask-codey.com/cheat-sheets/pandas-cleaning-function-cheat-sheet
