CSV Column Swapper
Rearrange, swap, and reorder CSV columns instantly with drag-and-drop. Upload CSV, reorder columns visually, and download the restructured file.
About
Column order in CSV files is rarely arbitrary. ETL pipelines, database imports, and reporting systems expect fields at precise positions. A single misaligned column causes silent data corruption: dates parsed as amounts, IDs mapped to names, categorical flags treated as numeric. This tool parses your CSV file according to RFC 4180 rules, auto-detects the delimiter (d ∈ {, ; \t |}), and lets you reorder columns via drag-and-drop or keyboard controls before rebuilding the output. It handles quoted fields containing embedded delimiters and newlines correctly. The parser runs entirely in your browser. No data leaves your machine.
Limitation: this tool treats the first row as a header by default. Files without headers can be processed by toggling the header option, in which case columns are labeled Col1, Col2, etc. Extremely wide files (> 500 columns) may exhibit slower drag interactions due to DOM rendering. For files exceeding 1 MB, parsing is offloaded to a Web Worker to keep the UI responsive.
Formulas
Delimiter auto-detection scores each candidate delimiter d by computing the consistency of field counts across the first n sample rows:
Where σ(counts) is the standard deviation of field counts per row using delimiter d, and is the mean field count. A perfect delimiter yields σ = 0 (identical column count in every row), maximizing the score. The delimiter with the highest score is selected.
Column remapping applies an index permutation vector P = [p0, p1, …, pk−1] to each row R:
Where k is the total column count and P is the user-defined column order. This runs in O(n × k) time where n is the row count.
Reference Data
| Delimiter | Symbol | Common Use | Auto-Detected | RFC 4180 |
|---|---|---|---|---|
| Comma | , | Standard CSV exports, spreadsheets | Yes | Yes |
| Semicolon | ; | European locales (Excel EU) | Yes | No (extension) |
| Tab | \t | TSV files, database dumps | Yes | No (extension) |
| Pipe | | | Legacy mainframe exports | Yes | No (extension) |
| Double Quote | " | Field enclosure character | N/A | Yes |
| CRLF | \r\n | Row terminator (Windows) | Auto-normalized | Yes |
| LF | \n | Row terminator (Unix/Mac) | Auto-normalized | Extension |
| Escaped Quote | "" | Literal quote inside quoted field | Handled | Yes |
| BOM (UTF-8) | \uFEFF | Excel UTF-8 exports | Stripped | N/A |
| Empty Field | ,, | Missing/null values | Preserved | Yes |
| Newline in Field | "a\nb" | Multi-line cell content | Preserved | Yes |
| Trailing Delimiter | a,b, | Some legacy systems | Preserved | Edge case |
| Mixed Quoting | a,"b",c | Partial quoting | Handled | Yes |
| UTF-8 Content | Unicode | International characters | Preserved | Extension |
| Max Columns | 500 | UI rendering limit | Soft limit | N/A |