Dataset Pivot Wider: long to wide for CSV & datasets
Pricing
from $0.14 / 1,000 output rows
Dataset Pivot Wider: long to wide for CSV & datasets
Turns a long table (one row per customer and month) into a wide one (one row per customer, one column per month) for a CSV / JSON file or an Apify dataset. Sum, mean, count, min, max, first or last of the values. Empty input = free demo.
Pricing
from $0.14 / 1,000 output rows
Rating
0.0
(0)
Developer
Actor Factory
Maintained by CommunityActor stats
0
Bookmarked
2
Total users
1
Monthly active users
3 hours ago
Last modified
Categories
Features
Share
Pivot a long CSV, JSON file or Apify dataset into a wide table
Turns "one row per customer and month" into "one row per customer, one column per month". For anyone who gets data in the long shape and needs the wide one: a scraper dataset with one row per product and day that should become one row per product with a column for every day, a CSV export with one row per region, product and quarter that a report wants as one row per region and product, survey answers stored as question / answer pairs. Name the columns, press Start, and download the wide rows as CSV, JSON or Excel from the dataset (or as one CSV file). It works from the Console form: no code, no spreadsheet pivot table.
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), and an output row is one row of the wide table. A table with 5,000 customers costs $1.00 however many months it has. The $5 monthly free credit covers about 25,000 output rows. Reading input rows is free. Failed runs, runs with no output rows and the demo are free. No scraping, no API keys.
Sample
Input rows (a dataset or a CSV file) with Index columns region, product; Names from quarter; Values from revenue; Aggregate sum; Prefix revenue_; Fill missing cells with 0:
| region | product | quarter | revenue |
|---|---|---|---|
| East | Tools | Q1 | 1,200 |
| East | Tools | Q2 | 1,450 |
| East | Garden | Q1 | 300 |
| East | Garden | Q2 | 420 |
| West | Tools | Q1 | 980 |
| West | Garden | Q1 | 150 |
| West | Garden | Q2 | 210 |
| West | Garden | Q2 | 40 |
| East | Tools | Q3 | 1,610 |
| West | Tools | Q3 | 1,005 |
Output (4 rows, 3 new columns):
| region | product | revenue_Q1 | revenue_Q2 | revenue_Q3 |
|---|---|---|---|---|
| East | Tools | 1200 | 1450 | 1610 |
| East | Garden | 300 | 420 | 0 |
| West | Tools | 980 | 0 | 1005 |
| West | Garden | 150 | 250 | 0 |
West / Garden had two rows for Q2 (210 and 40), which were summed to 250. East / Garden and West / Garden have no Q3, and West / Tools has no Q2, so those cells took the fill value 0 (leave it empty to get null).
What it does
- Groups rows by your index columns: one output row for every distinct combination, in the order the combinations first appear. Empty values count as equal; the number
1and the text"1"are the same value. - Makes one new column per distinct value of "Names from", in the order the values first appear (stable, not alphabetical). Names are exact text and case-sensitive (
Aandaare two columns). Use Prefix for new columns to getrevenue_Q1instead ofQ1, or to keep numeric names like2024readable. - Fills the cells from one or more value columns. With several value columns the new columns are named
<name>_<column>(Jan_qty,Jan_price). - Seven ways to combine rows that land in the same cell:
first(default),last,sum,mean,count,min,max.firstandlastkeep the value exactly as it was (text stays text,007stays007) and skip empty values.sum,mean,minandmaxread numbers (also written as1,200,$5or12%), and values that are not numbers are ignored and counted in the run summary.countcounts the non-empty values. - Fills missing cells (no row for that index and name) with the value you give, or null. A number such as
0is written as a number when you sum, average, count or take the min / max. - Two kinds of input: Apify datasets (resource picker, read permission only) and public CSV / TSV / JSON / NDJSON file URLs, mixed freely and pivoted together as one table. Encoding (UTF-8, Shift JIS, Windows-1252) and delimiter (comma, semicolon, tab, pipe) are detected.
- Nested fields: use dots, for example
owner.idas an index column. - CSV copy: turn on Also save a CSV file to get the wide rows as one file in the key-value store (record
pivoted.csv, UTF-8 with BOM so Excel opens it correctly).
Input example
{"fileUrls": ["https://raw.githubusercontent.com/mwaskom/seaborn-data/master/flights.csv"],"indexColumns": ["year"],"namesFrom": "month","valuesFrom": ["passengers"]}
One row per year with a column for each month. A dataset with the average pulse per person and activity at each time point:
{"datasetIds": ["<id>"], "indexColumns": ["id", "kind"], "namesFrom": "time", "valuesFrom": ["pulse"], "aggregate": "mean", "namePrefix": "pulse_"}.
Output
- Dataset: the wide rows, index columns first, then the new columns. Download as CSV, JSON, Excel and more from the Console.
pivoted.csv(key-value store, only with Also save a CSV file).- STATS record (key-value store):
inputRows,outputRows,chargedRows, the list of newcolumns, rows read per source insources,rowsWithoutName,valuesNotNumericandnotes.
Rules worth knowing
- Rows with an empty "Names from" value are skipped (there is no column to put them in) and counted in the run summary.
- A wrong column name stops the run before anything is written or charged. The error names the missing column and lists the columns that were found. Names are case-sensitive; a column only has to exist in one row.
- A new column that would have the same name as an index column gets
_2added (k_2), and the run summary says so. - Values keep their type in the output for
firstandlast. A CSV file has no types, so its values stay text exactly as written. The numeric aggregates write numbers. countof nothing is 0. A cell with no row at all takes the fill value, not 0, unless you set it so.
Limits (cannot be raised by input)
- Up to 50,000 input rows and 10 minutes per run. A pivot needs every row, so all rows are held in memory. If there are more rows than Max input rows, the run stops without pivoting or charging rather than pivoting a partial read, which would give wrong numbers. If the 10-minute limit is hit, the run also stops without writing or charging. Split the data first (for example by a column value).
- Up to 500 new columns per run (distinct names times value columns). Over that the run stops with a clear message and nothing is charged: pick a names column with fewer distinct values or filter the rows first.
- 20 datasets and files per run; 100 MB per file (a JSON array: 50 MB, because it has to be read whole; use NDJSON, one object per line, for bigger files); 20 index columns and 20 value columns.
- Source URLs must be public
httporhttpslinks. 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 writes only the first rows of the result that fit the budget (never past it) and says so in the run summary. If the budget is lower than the price of one row, the run stops at once without charging.
On the Apify Free plan, the $5 of monthly platform credit covers about 25,000 rows a month.
Use cases
- Turn a scraper dataset with one row per product and date into one row per product with a column per date
- Reshape a long export (region, product, quarter, revenue) into the wide table a report or import expects
- Count how often each value occurs per customer, one column per value (
count) - Average repeated measurements per person and time point
- Prepare a one-row-per-record file for the next Actor in a workflow
FAQ
Does it change my source dataset? No. It only reads it and writes a new dataset.
Why is a cell empty? No row had a value for that index and name. Set Fill missing cells with (for example 0).
Why is my sum a text? It is not: sum always writes numbers. With first or last the value is copied as it was, so a CSV value stays text.
Can I do the opposite (wide to long)? This Actor only goes from long to wide.
What if there are more than 500 distinct names? The run stops before writing anything. Filter the rows (for example to the top names) or use another names 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 — explode array fields into rows, unpivot wide columns into name/value rows, or pivot back
- Group By & Aggregate — group dataset or CSV rows by columns and get counts, sums, averages, medians and pivot tables, one row per group
- Dataset Sort — sort a CSV, JSON file or dataset by one or more columns: numbers, text or dates, natural order, top-N and dedupe
- Filter CSV, JSON or Dataset Rows by Condition — keep only the rows of a CSV, JSON file or dataset that match simple conditions like country = US or price > 100
- Merge Datasets — combine several datasets or CSV/JSON files into one, with columns aligned