Pivot a Table
Pivot a Table
The Pivot node spreads the unique values of one column into new columns, filling each cell by aggregating a values column. It's the classic "long → wide" reshape.
You'll use: File Input → Pivot → File Output.
File Input
sales_long.csv
Pivot
index region · columns month · values amount
File Output
sales_wide.csv
Steps
- File Input — select your long-format dataset.
- Pivot — set:
index: ["region"]— the row key(s)columns: "month"— the column whose values become new columnsvalues: "amount"— the column to aggregate into the cellsaggfunc: "sum"— how to combine collisions (defaultsum)
- File Output — write the wide table.
Before / after
Before
| region | month | amount |
|---|---|---|
| North | Jan | 100 |
| North | Feb | 120 |
| South | Jan | 80 |
3 rows · 3 cols
Pivot (index=region, columns=month, values=amount, aggfunc=sum)
After
| region | Jan | Feb |
|---|---|---|
| North | 100 | 120 |
| South | 80 | null |
2 rows · 3 cols
South has no Feb row in the source data, so its Feb cell comes out null
(pivot_table doesn't fill missing index/column combinations by default) —
add a Fill Nulls node after Pivot if you want
those cells to read 0 instead.
Tips
- New column names come from the values found in
columnsat run time. - Need the inverse (wide → long)? Use Unpivot.