---
name: csv-clean
description: Normalises a messy CSV into a tidy, machine-readable one and logs every change. Use this skill when the user asks to clean, tidy, deduplicate or normalise a CSV or spreadsheet export, fix inconsistent date or number formats, or prepare a delimited file for import.
allowed-tools: [Read, Write, Glob]
license: MIT
---

# CSV Clean

Cleaning data silently is how bad numbers reach a dashboard. This skill produces
a tidy file **and** a log of every row it changed or dropped, so the two can be
reviewed together.

## When this applies

- "clean up raw/orders.csv"
- "this export has duplicate rows and mixed date formats"
- "make this CSV importable"

Do not activate for analysis questions ("what was March revenue?") or for
generating sample data.

## Procedure

1. **Read the file and detect the dialect** — delimiter, quote character, line
   terminator, and whether the first row is a header. Say what you detected.
2. **Normalise the header.** `snake_case`, ASCII, no units in the name unless
   they disambiguate (`Amount (USD)` → `amount_usd`). Duplicate headers get a
   numeric suffix; empty headers become `column_<n>`.
3. **Trim and unquote every cell.** Strip surrounding whitespace, collapse
   internal runs, remove thousands separators and currency symbols from numeric
   columns.
4. **Infer a type per column** from all values, not the first one. A column with
   a single non-numeric value stays text — report the offending row instead of
   coercing it to `NaN`.
5. **Normalise dates to ISO-8601.** When a column mixes `MM/DD` and `DD/MM`,
   resolve each value by its day-of-month where that is unambiguous, and list
   every value you could not resolve. Never guess silently.
6. **Deduplicate on the full row** unless the user names a key column. Record
   how many duplicates were removed and which keys they carried.
7. **Drop rows only for a stated reason** (missing required field, unparseable
   date) and list every dropped row in the report.
8. **Write two files**: the tidy CSV, and a cleaning report naming every step
   with row counts in and out.

## Guardrails

- Never modify or delete the source file — the raw export is the audit trail.
- Never shell out to delete directories or "clean up" afterwards.
- Never invent a value to fill a gap. Empty stays empty, or the row is dropped
  and reported.

## Output contract

The tidy CSV has a `snake_case` header row, no quoted fields, no currency
symbols, no empty cells in required columns, and ISO-8601 dates. The report
lists row counts for every step.
