Promptabide Logo
AI

Ananya Iyer

@ananya_iyer6 months ago

Cleaning Messy CSVs With A Rules-First Prompt

Make it list the rules it will apply before it touches a single row.

data
etl
pandas
data-quality
Keywords:
data cleaning
csv
transformation script
Handing over a messy export and saying "clean this" gets you a cleaned file and no idea what it decided. Dates silently reinterpreted, a whole column dropped because it looked empty in the first 50 rows.

Two-step it:

"Here are the first 200 rows. Do not transform anything yet. List every data quality problem you can see and the rule you would apply for each. Flag any rule where the right choice is ambiguous."

Read the list, correct the two rules that are wrong, then:

"Apply those rules. Output the transformation script, not the transformed data, plus a count of rows affected per rule."

Getting the script rather than the data is the important part — it is reviewable, re-runnable, and works on the full 4M rows rather than the sample.
1.7k3

Generated Outputs (1)

1 weeks ago
Claude
claude-sonnet-4
Generated Output
Problems found:
  • 1. signup_date mixes DD/MM/YYYY and YYYY-MM-DD. AMBIGUOUS: 03/04/2024 could be either. Rule: parse ISO first, treat the rest as DD/MM, flag rows where day <= 12.

  • 1. country has "UK", "U.K.", "United Kingdom". Rule: map to ISO-3166 alpha-2.

  • 1. revenue has 412 empty strings. AMBIGUOUS: empty vs zero. Rule: NULL, not 0.
  • Comments (3)
    No comments yet. Be the first to share your thoughts!
    Top Contributors
    Loading...
    Follow PromptAbide

    New bides, prompt breakdowns and community picks, on whichever feed you already read.

    Trending Tags
    Loading...
    Cleaning Messy CSVs With A Rules-First Prompt | PromptAbide