A Cleaning Routine

A Cleaning Routine: A Cleaning Function, Step by Step, Saving the Clean Data: to_csv and to_excel.

Updated

  1. A Cleaning Function, Step by Step (Journeyman): 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.
  2. Saving the Clean Data: to_csv and to_excel (Apprentice): A clean table lives only as long as the notebook's kernel, so to_csv with index=False saves it as a file the next notebook can load, to_excel saves a workbook for people who use Excel, and keeping data/raw and data/clean folders, with a save function that refuses the raw folder, means the raw file is never written over.