What does the CSV Transposer do?
The CSV Transposer flips the axes of CSV spreadsheets and delimited tables, converting rows into columns and columns into rows (2D matrix transposition). It automatically handles ragged grids by padding uneven rows and preserves RFC 4180 quotation formatting.
Core Concepts
- Matrix Transposition ($M^T$): Converts an $N \times M$ table into an $M \times N$ structure, allowing row-based metrics to become column headers and vice versa.
- Ragged Row Normalization: Automatically calculates the maximum column width and safely fills any missing cells with a configurable placeholder.
- RFC 4180 Compliance: Retains multi-line fields and escaped double quotes throughout rotation.
How to use the tool?
- Input CSV Data: Paste your CSV data into the input box or click Load Sample.
- Configure Padding: Enter an optional fill string for ragged rows (default is empty string).
- Transpose & Export: Click Transpose CSV, then click Copy or Download.
Related Developer Utilities
- CSV Column Sorter: Sort CSV rows by any column in ascending or descending order.
- CSV Row Deduplicator: Remove duplicate rows from CSV spreadsheets.
- CSV to JSON Converter: Convert tabular CSV data into structured JSON objects.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/csv/csv-transposer) for programmatic integration.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
payload |
String or Array | The raw CSV text payload OR a native JavaScript array-of-arrays to transpose. Aliases: rawText, text, input, csv. |
"Q1,Q2\n100,200" |
options |
Object | Optional transposition configurations. | { "fillMissing": "N/A" } |
options.fillMissing |
String | Value to populate for missing cells in uneven rows. | "" |
API Request Payload Examples
cURL (String Payload)
curl -X POST https://blueutils.com/api/csv/csv-transposer \
-H "Content-Type: application/json" \
-d '{
"payload": "Metric,Q1,Q2\nRevenue,150,175\nProfit,60,80",
"options": {
"fillMissing": ""
}
}'Python (Array Payload)
import requests
url = "https://blueutils.com/api/csv/csv-transposer"
payload = {
"payload": [["Metric", "Q1", "Q2"], ["Revenue", "150", "175"], ["Profit", "60", "80"]],
"options": {
"fillMissing": ""
}
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonPayload = "{\"payload\": \"A,B\\n1,2\"}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/csv/csv-transposer"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}API Response Parameters
| Name | Type | Description | Example |
|---|---|---|---|
isValid |
Boolean | Indicates whether the transposition succeeded. | true |
result |
String | Resulting transposed CSV text. | "Metric,Revenue,Profit\nQ1,150,60\nQ2,175,80" |
data |
Array | Native array-of-arrays representation of the transposed CSV. | [["Metric", "Revenue"], ["Q1", "150"]] |
originalSize |
Number | Byte size of the original unformatted data. | 41 |
resultSize |
Number | Byte size of the formatted string output. | 41 |
originalRowCount |
Number | Number of rows in the input matrix. | 3 |
originalColumnCount |
Number | Maximum columns in the input matrix. | 3 |
newRowCount |
Number | Row count after transposition. | 3 |
newColumnCount |
Number | Column count after transposition. | 3 |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"result": "Metric,Revenue,Profit\nQ1,150,60\nQ2,175,80",
"data": [
["Metric", "Revenue", "Profit"],
["Q1", "150", "60"],
["Q2", "175", "80"]
],
"originalSize": 41,
"resultSize": 41,
"originalRowCount": 3,
"originalColumnCount": 3,
"newRowCount": 3,
"newColumnCount": 3,
"fillMissing": ""
}Error Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "CSV input cannot be empty."
}Rate Limit Exceeded Response (HTTP 429 Too Many Requests)
{
"error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}Why use an API to transpose CSV rows and columns?
Integrating the CSV Transposer API into CI/CD pipelines, automated ETL pipelines, or autonomous agent workflows provides several practical advantages:
- Rapid Script Validation: Enables developers and business analysts to quickly pivot reporting tables between wide and tall schemas programmatically.
- Optimized Token Efficiency for AI Agents: Offloading 2D array inversion and RFC 4180 cell padding to an external API significantly cuts prompt and completion token consumption for autonomous agents.
- Deterministic Accuracy Without Hallucinations: Language models frequently swap indices or corrupt ragged lines when rotating large matrices. Delegating processing to a deterministic API guarantees 100% computational accuracy every time without token overhead.
Native Usage
How to achieve the same task locally without external dependencies using native operating system utilities and scripting languages:
Windows (CMD / PowerShell)
Using native PowerShell array transformations:
# Transpose CSV matrix
$rows = Get-Content -Path "input.csv" | ForEach-Object { ,($_.Split(',')) }
$maxCols = ($rows | Measure-Object -Property Length -Maximum).Maximum
$transposed = for ($c = 0; $c -lt $maxCols; $c++) {
($rows | ForEach-Object { $_[$c] }) -join ','
}
$transposed | Set-Content -Path "output.csv"Linux / Unix (Bash / Shell)
Using standard Linux awk:
# Transpose comma-delimited matrix in Bash
awk -F',' '{
for (i=1; i<=NF; i++) {
a[i,NR] = $i
}
if (NF>max_nf) max_nf = NF
}
END {
for (i=1; i<=max_nf; i++) {
for (j=1; j<=NR; j++) {
printf "%s%s", a[i,j], (j==NR ? "\n" : ",")
}
}
}' input.csv > output.csvPython
Using the Python standard library zip() and csv module:
import csv
with open("input.csv", mode="r", encoding="utf-8") as infile:
reader = csv.reader(infile)
transposed = list(zip(*reader))
with open("output.csv", mode="w", newline="", encoding="utf-8") as outfile:
writer = csv.writer(outfile)
writer.writerows(transposed)
print("CSV matrix transposed successfully.")Java
Using standard Java 2D arrays:
import java.nio.file.*;
import java.util.*;
public class TransposeCsvExample {
public static void main(String[] args) throws Exception {
List<String> lines = Files.readAllLines(Paths.get("input.csv"));
if (lines.isEmpty()) return;
List<String[]> matrix = new ArrayList<>();
int maxCols = 0;
for (String line : lines) {
String[] parts = line.split(",");
matrix.add(parts);
if (parts.length > maxCols) maxCols = parts.length;
}
List<String> transposed = new ArrayList<>();
for (int c = 0; c < maxCols; c++) {
StringBuilder row = new StringBuilder();
for (int r = 0; r < matrix.size(); r++) {
String[] cur = matrix.get(r);
row.append(c < cur.length ? cur[c] : "");
if (r < matrix.size() - 1) row.append(",");
}
transposed.add(row.toString());
}
Files.write(Paths.get("output.csv"), transposed);
System.out.println("CSV matrix transposed successfully.");
}
}