# Transpose Table: swap rows and columns of CSV (`ucchiii/transpose-table`) Actor

Swaps the rows and columns of a table: Apify dataset, CSV or JSON file, or pasted CSV text. Pick a column to become the new headers. Works from the Console form. Empty input = free demo.

- **URL**: https://apify.com/ucchiii/transpose-table.md
- **Developed by:** [Actor Factory](https://apify.com/ucchiii) (community)
- **Categories:** Developer tools, Automation, Integrations
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.14 / 1,000 output rows

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

**Swap the rows and columns of a table**

**Returns your table turned on its side: every column becomes a row and every row becomes a column.** For anyone who has a CSV, a JSON list or an Apify dataset laid out the wrong way round for the next step: a report with months down the side that a chart wants across the top, a scraper result with one product per row that you want to compare side by side, a spreadsheet export that a form or a database import expects the other way. Pick the column whose values should become the new headers, press Start, and download the result as CSV, JSON or Excel from the dataset. It works from the Console form: no code, no spreadsheet formulas.

**Try it free: leave all inputs empty and press Start** (the demo is not charged and its rows carry `_demo: true`).
**$0.20 per 1,000 output rows**, charged per row ($0.0002 a row). A transposed table has one output row per column of your input table, so a table with 12 columns costs $0.0024. The $5 monthly free credit covers about 25,000 output rows. Failed runs, runs with no output rows and the demo are free. No scraping, no API keys.

### Sample

Input (a dataset, a CSV file or pasted text), **Header column**: `region`

| region | jan | feb | mar |
|---|---|---|---|
| North | 120 | 135 | 150 |
| South | 80 | 90 | 95 |
| West | 60 | 72 | 66 |

Output (first column named `month` with **Name of the first output column**):

| month | North | South | West |
|---|---|---|---|
| jan | 120 | 80 | 60 |
| feb | 135 | 90 | 72 |
| mar | 150 | 95 | 66 |

Without a header column the new columns are called `row_1`, `row_2`, ... and the `region` column stays in the result as a row of its own.

### What it does

- **Transposes** a table: the old column names go into the first column of the result (named `field` unless you choose another name), the old rows become columns.
- **Header column**: the values of the column you name become the new column names, and that column is not repeated as a row. Empty or repeated values get safe names (`row_3`, `a_2`).
- **Three kinds of input**: Apify datasets (resource picker, read permission only), public CSV / TSV / JSON / NDJSON file URLs, and a table pasted as text. Mix them in one run: each table is transposed on its own and, with more than one table, every row has a `_source` column.
- **File details handled for you**: encoding (UTF-8, Shift JIS, Windows-1252), delimiter (comma, semicolon, tab, pipe) and numbers are detected. A JSON object that wraps the rows needs a **Records path** such as `products`. CSV without a header line works with **First row is a header** turned off.
- **Nested data**: nested objects become dotted columns (`owner.name`; choose the separator). Arrays stay arrays.
- **Missing values** become null, so rows with different fields still line up.
- **Safe by default**: **Max input rows** (default 1,000, maximum 10,000) bounds the width of the result; when it cuts your table, `inputTruncated` is `true` in the run summary.

### Input example

```json
{
  "fileUrls": ["https://dummyjson.com/products?limit=10&select=title,price,rating,stock"],
  "recordsPath": "products",
  "headerColumn": "title",
  "firstColumnName": "measure"
}
```

Pasted text: `{"csvText": "metric,q1,q2\nrevenue,120,135\ncosts,90,95", "headerColumn": "metric", "firstColumnName": "quarter"}`.
A dataset: `{"datasetIds": ["<id>"], "headerColumn": "region"}`.

### Output

- **Dataset**: the transposed rows, one per column of the input table. Download as CSV, JSON, Excel and more from the Console.
- **STATS** record (key-value store): `inputRows`, `outputRows`, `inputTruncated`, `chargedRows`, one entry per table in `tables` (source, input rows, output rows, new columns) and per-source `errors`.

### Rules worth knowing

- Rows become columns, so a table with many rows gives a very wide result. Only the first **Max input rows** rows are read.
- Transposing twice with the right header column gives back the original table (set **Header column** to `field` the second time).
- Values keep their type: numbers stay numbers, empty cells stay null. In pasted or downloaded CSV text, numbers are recognized, but values with a leading zero (`007`) or more than 15 digits stay text.
- Header values are turned into text for the new column names (`1.0` becomes `1`).
- The first column is named `field`. If one of your header values is also `field`, it becomes `field_2`.

### Limits (cannot be raised by input)

- 20 tables per run; 50 MB per file; 10,000 input rows and 100,000 output rows per table
- Source URLs must be public `http` or `https` links. Addresses on internal networks (localhost, private ranges, cloud metadata) are blocked, also after redirects. Excel files are not read (save them as CSV first)

### Pricing

Pay per event: **$0.20 per 1,000 output rows** (event `row`, $0.0002 per output row). Reading input rows is free. Nothing is charged when the run fails or produces no rows. Set a maximum charge per run: the Actor then stops producing rows at that budget (never past it) and says so in `truncated`.
On the Apify Free plan, the $5 of monthly platform credit covers about **25,000 rows** a month.

### Use cases

- Months, quarters or years down the side to across the top (or back) for charts and slides
- One product, listing or company per column for a side-by-side comparison
- Flipping a key/value export so each record is a column, or each column a record
- Preparing a CSV for a tool that expects the other orientation

### FAQ

**Does it change my source dataset?** No. It only reads it and writes a new dataset.
**Why are some cells empty?** The source rows did not all have the same fields. Missing values are null.
**My JSON file is an object, not an array.** Give **Records path** (for example `data.items`). Without it, the only array of objects in the file is used.
**Can I use a column with repeated values as the header?** Yes. Repeats get a `_2`, `_3` suffix so no column is lost.
**What happens to the first column of my table when I leave Header column empty?** It is kept: it becomes the first row of the result, with its old column name in the first column.

If this Actor saved you time, a rating on the Store helps others find it.

### More tools from the same developer

- [Dataset Explode & Unpivot](https://apify.com/ucchiii/dataset-explode-unpivot) — explode array fields into rows, unpivot wide columns into name/value rows, or pivot back
- [CSV to Excel Converter](https://apify.com/ucchiii/csv-xlsx-converter) — convert CSV, TSV, Excel XLSX, JSON and NDJSON files or Apify datasets into each other
- [Dataset Transform](https://apify.com/ucchiii/dataset-transform) — flatten, filter, rename and convert any Apify dataset, export CSV / JSON / JSONL with a link
- [JSON to CSV Converter](https://apify.com/ucchiii/json-to-csv) — turn nested JSON files or datasets into one flat CSV file
- [Flatten JSON to CSV](https://apify.com/ucchiii/flatten-json) — flatten nested JSON into flat rows with the separator you choose

# Actor input Schema

## `datasetIds` (type: `array`):

Datasets to transpose (the 'defaultDatasetId' of a finished run). You can paste a dataset URL from Apify Console too. Each dataset is transposed as its own table. Up to 20 tables per run in total. Leave this, 'File URLs' and 'CSV text' empty to run a free demo on a built-in sample (not charged).

## `fileUrls` (type: `array`):

Public http(s) links to CSV, TSV, JSON or NDJSON files (up to 50 MB each). Each file is transposed as its own table. Links to internal networks are blocked.

## `csvText` (type: `string`):

A table pasted as text: CSV, TSV, or JSON. The first line is the header unless 'First row is a header' is off. Example: 'metric,q1,q2' on the first line, then 'revenue,120,135'.

## `inputFormat` (type: `string`):

Format of the files in 'File URLs' and of the 'CSV text'. 'auto' uses the file extension, content type and content. Ignored for datasets. Default: auto.

## `recordsPath` (type: `string`):

For a JSON file whose rows sit inside an object, the dot path to the array of rows, e.g. 'products' or 'data.items'. Empty = the file is an array, or the only array of objects in it is used.

## `inputHasHeader` (type: `boolean`):

CSV, TSV and JSON arrays of arrays: whether the first row holds the column names. Turn off and the columns are named column_1, column_2 ... and the first row is data. Ignored for datasets and JSON objects, which carry their own names. Default: on.

## `headerColumn` (type: `string`):

Name of the column whose values become the new column names (for example 'region' or 'metric'). That column is not repeated as a row. Empty = the new columns are named row_1, row_2 ... in the order of your rows. Nested names use the flatten separator (owner.name).

## `firstColumnName` (type: `string`):

The first column of the result holds the old column names. This is its name (for example 'month' or 'metric'). Default: field.

## `maxRows` (type: `integer`):

Rows of your table become columns of the result, so only this many input rows are read. When there are more, 'inputTruncated' is true in the run summary. Maximum 10,000. Default: 1,000.

## `flattenSeparator` (type: `string`):

Text that joins nested key names of datasets and JSON files, e.g. '.' gives owner.name and '\_' gives owner_name. Max 5 characters. Default: '.'.

## Actor input object example

```json
{
  "inputFormat": "auto",
  "inputHasHeader": true,
  "firstColumnName": "field",
  "maxRows": 1000,
  "flattenSeparator": "."
}
```

# Actor output Schema

## `results` (type: `string`):

The transposed table: one row per column of the input table. Download as CSV, JSON, Excel and more.

## `stats` (type: `string`):

Record STATS: input and output row counts, the new columns per table, whether the input was cut at the row limit, rows charged and per-source errors.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("ucchiii/transpose-table").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("ucchiii/transpose-table").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call ucchiii/transpose-table --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,ucchiii/transpose-table"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/jSfqXfQ9YgcdqcFqA/builds/ZxiV46uPiPaTu2CKb/openapi.json
