Overview
Introduction
Two columns landed in the wrong order after a merge or export, and reinserting from scratch is more work than it needs to be. This tool just swaps two columns directly.
It's a light, targeted alternative to deleting and reinserting when only two columns need to trade places.
What Is CSV Column Swapper?
A structural CSV tool that exchanges the positions of exactly two columns, each identified by 0-based index or exact header name, across every row.
Every other column, and every other row's ordering, is left completely untouched.
How CSV Column Swapper Works
The input is parsed and padded to a uniform grid, then both column references are resolved to indices using the header row.
For every row, the cells at those two indices are exchanged with each other, and the grid is re-serialized back into CSV text.
When To Use CSV Column Swapper
Use it when two columns in an export are in the wrong relative order and every other column is already correct.
It's also handy for quick experimentation, testing how a downstream tool behaves with two fields transposed.
Often used alongside CSV Column Sorter, CSV Column Rotator and CSV Column Inserter.
Features
Advantages
- Touches only the two specified columns, leaving everything else in the CSV completely stable.
- Accepts a mix of index and header-name references for the two columns.
- Guards against swapping a column with itself, catching an easy copy-paste mistake.
Limitations
- Only swaps exactly two columns per run; a full reorder needs either CSV Column Sorter or several chained swaps.
- Column references must resolve uniquely; duplicate header names can make a name-based reference ambiguous.
Examples
Best Practices & Notes
Best Practices
- Use header names for clarity when the CSV's column order might not match what you remember from an index.
- Chain repeated swaps, rather than reaching for a full sort, when only a couple of columns are out of place.
- Double-check both references resolve to different columns before running, to avoid a wasted no-op swap.
Developer Notes
Resolves both column references independently via the shared index-or-header-name lookup, then performs a simple three-line temp-variable-free swap (`next[indexA] = row[indexB]; next[indexB] = row[indexA]`) per row.
CSV Column Swapper Use Cases
- Correcting two columns that landed in the wrong relative order after a merge or export
- Quickly testing how a downstream import behaves with two fields transposed
- Reordering a CSV incrementally via a series of two-column swaps
Common Mistakes
- Referencing the same column twice by accident, index and header name both pointing at the same column.
- Expecting more than two columns to move; only the two specified columns change position.
Tips
- If several columns need reordering, it's often faster to use CSV Column Sorter for a full alphabetical pass instead of many manual swaps.
- Combine with CSV Column Renamer afterward if the swap also calls for clearer header names.