One whitespace-cleaning lesson with an exercise, answer and synthetic CSV files. Full version: 20 lessons and trilingual materials.
Read the lesson, clean dirty.csv yourself, then compare with expected.csv. You can run clean.py with Python 3.10+. It does not overwrite the source.
03 · Whitespace and invisible characters
Problem
Names contain tabs, line breaks, nonbreaking spaces and zero-width spaces that defeat matching or join words incorrectly.
Rule and input contract
For this name field, treat tabs, line breaks and nonbreaking spaces as word separators. Remove zero-width spaces and collapse runs of ordinary spaces to one space.
Original input · 4 records
| Record | name_raw |
|---|---|
| 1 | ␠␠Ana␠␠␠López␠␠ |
| 2 | Luis Pérez |
| 3 | Martínez |
| 4 | ⇥María↵Sol⇥ |
dirty.csv · expected.csv · cleaned.csv · excel.pq
Excel procedure (Power Query reference)
Remove the zero-width space first. Replace tab, CR, LF and NBSP with spaces. Use Text.Split, remove empty fragments and recombine with Text.Combine.
Note: the canonical answers are the Python results (expected.csv). The bundled Power Query M queries are a reference for Excel users: set CsvPath to your local path before running them, and expect small adjustments for your Excel version. For case 18 the M query only maps the sample values; the Python version performs general NFC normalization.