---
name: clean-a-spreadsheet-safely
description: "Clean a spreadsheet or CSV to an agreed column contract without losing information: keep IDs as text, convert only unambiguous dates, honour declared missing values and keep genuine repeat rows. Use when someone asks to clean, tidy or standardise a spreadsheet or export before analysis or import."
license: CC-BY-4.0
metadata:
  author: Raq.com
  version: "2026-11-22"
  homepage: https://skills.raq.com/skills/clean-a-spreadsheet-safely
---

# Clean a spreadsheet without losing information

Apply the column rules a data owner has agreed, preserving uncertainty wherever a cleaner would otherwise silently alter a record.

## When to use this skill

- Someone wants a messy export tidied before analysis, import or sharing.
- The data has IDs with leading zeros, mixed date formats or placeholders such as NA, N/A or blanks.
- Someone wants duplicates removed and it is not clear whether the repeated rows are real records.

## When not to use it

- Rebuilding a file whose rows, quotes or columns broke during import. Use the CSV import rescue skill first.
- Filling in missing values or correcting suspected errors. The skill marks them for the data owner; imputation is an analysis decision.

## What you need

- Raw table and the column contract for identifiers, dates, amounts and missing values.
- The intended unit of observation and any authorised duplicate-removal rule.

## Ask before you start

If any of these are missing or unclear, ask before doing the work.

- What does each row represent, such as one customer, one order or one transaction? That decides whether repeated rows are duplicates.
- Which columns are identifiers, dates and amounts, and what date order and decimal style does the source use?
- Which values mean missing, and in which columns, such as blank, NA or N/A?

## Method

1. Work on a copy that keeps the original row order and row count. Write down each transformation before applying it.
2. Import every column as text first, with automatic type detection and default missing-value markers switched off, then convert column by column. Excel strips leading zeros, Power Query guesses types from the first 200 rows, and pandas reads NA and N/A as missing in every column unless told otherwise.
3. Use the declared date convention. With an unknown convention, convert only dates whose reading is certain, such as ISO dates or a day above 12. Keep an ambiguous value as supplied and record its location.
4. Convert amounts using the stated locale and distinguish numeric zero from an empty amount. Apply missing markers only to the columns they are declared for. Never reconstruct leading zeros already lost in a numeric export.
5. Remove a row only under a declared identity rule for the unit of observation. Keep repeated customer IDs when the rows are transactions.
6. Compare row counts and the count of non-missing values in each converted column before and after. Return the coordinates of every unresolved cell for the data owner.

## Checks before you deliver

- A repeated person can make several purchases. Removing a row requires a record-level identity rule.
- A syntactically valid date in both day-first and month-first formats offers no evidence about which was intended.
- Default import settings turn NA, N/A and blank into missing in every column, so a real code such as the area NA disappears.
- Numeric import turns 009 and 9 into the same number, merging two different identifiers.
- Turning a blank amount into zero changes totals and averages.

## How to present the result

Lead with what changed and the row counts before and after, which should match unless a declared rule removed rows. Then give the cleaned table, followed by a list of cells left as supplied for the owner to decide, each with its row, column, value and the question to answer. Include the column rules applied so the clean can be repeated.

## Worked example

**Request:** Clean the purchases. Date order is unknown. Empty prices mean missing. Pounds use a decimal point.

**Supplied material:**

```text
customer,date,price
00123,03/04/2026,
00123,2026-04-05,0
```

**Answer:** Keep both purchases under the text ID 00123. Leave the first date as 03/04/2026 for the owner to resolve and its price as missing. The second row is dated 2026-04-05 and has a genuine price of zero.

## Structured output for tests

For an ordinary job, answer in the format above and point back to the supplied evidence. Use this structure only for the test cases published with this skill, or when someone asks for structured JSON.

Return rows in original order, preserving the actual column names and all unmodified fields. Keep identifiers as text, established dates as ISO dates, declared amounts as numbers and agreed missing markers as null. Keep unresolved values as supplied and list their coordinates in review as dataRow.column, starting at data row 1.

## Sources

- [W3C: Metadata vocabulary for tabular data](https://www.w3.org/TR/tabular-metadata/): The W3C Recommendation lets each column declare its datatype and the strings that count as null, and defines a primary key whose values must be unique for each row. The skill follows the same idea: a per-column contract decides what counts as missing, a date or an identifier.
- [Microsoft Power Query: data types](https://learn.microsoft.com/en-us/power-query/data-types): For Excel, CSV and text files Power Query detects column types automatically from the first 200 rows, and it interprets dates and numbers using the locale. Microsoft's example shows UK day/month dates failing under a US locale until the column is converted with the right locale.
- [Microsoft Excel: keeping leading zeros and large numbers](https://support.microsoft.com/en-us/office/keeping-leading-zeros-and-large-numbers-1bf7b935-36e1-4985-842f-5dfa51f85fe7): Microsoft says Excel automatically removes leading zeros, shows large numbers in scientific notation and keeps only 15 digits, and recommends setting such columns to text when importing through From Text/CSV.

Test cases and an answer checker for this skill: https://skills.raq.com/skills/clean-a-spreadsheet-safely
