CSV Transposer
Swap rows and columns of a CSV table.
Overview
The CSV transposer swaps the rows and columns of a CSV table — what was the first column becomes the first row, what was the second column becomes the second row, and so on. Headers and data are treated uniformly so the transpose is a clean pivot of the entire grid.
It's the move when a dataset arrives in the wrong orientation: metrics across the top with dates down the side, when your downstream tool wants metrics down the side and dates across the top. Analysts, BI engineers, and anyone wrangling exports from a reporting tool use a csv transpose to fix shape without rewriting upstream queries.
How it works
CSV is parsed per RFC 4180, then loaded into a two-dimensional array. The output array swaps indices: out[i][j] = in[j][i]. Ragged rows are padded with empty cells so the transpose is always rectangular — otherwise the round-trip would lose information.
The first column of the output (originally the header row) is treated like any other column, so the original header values appear in the first column of the result. If you need them back as a header row, transpose, edit, and transpose again.
Examples
Input:
day,a,b,c
Mon,1,2,3
Tue,4,5,6
Output:
day,Mon,Tue
a,1,4
b,2,5
c,3,6
Input:
metric,Q1,Q2
revenue,100,150
cost,40,50
Output:
metric,revenue,cost
Q1,100,40
Q2,150,50
FAQ
Does it preserve quoted fields?
Yes. Embedded commas, doubled quotes, and CRLF line endings inside cells survive the transpose unchanged — the quoting is re-applied on output where the value still needs it.
What if rows have different lengths?
Short rows are padded with empty cells so the matrix is rectangular before transposing. The output will be rectangular too, so the longest row in the input dictates the column count of the output.
Is the operation symmetrical?
Transpose twice and you're back to the original. That's a useful sanity check when you're not sure whether you've already pivoted a file once.