data management
slug: step-transposeConverts rows into columns (and vice versa) for easier analysis or visualization. Optionally uses a column’s values as new column headers.
id column is specified, its values are used as column names in the transposed dataset.transpose() function to swap rows and columns.Builds a new dataset with:
name column representing original variable namescol0, col1, …) or names from the id columnextras.Important: Any formatting, labels, or options applied to the original columns are carried forward to the resulting transposed rows. For example, a column formatted as a dollar amount will maintain that formatting in the transposed row labeled by that column.
id (string) – Column whose values will become the new column headers. If omitted, default column names col0, col1, etc., are used.id, the column must exist and contain unique or meaningful valuesdata: Transposed dataset as an array of rowspdv: Updated PDV metadata (e.g., hides original id column and renames name label to Properties)extras: Includes 'transposed' => true flagoutputType: 'array'steps:
- loadInline:
data:
# Young Segment
- {user: bob, age: 22, income: 38000, spend: 800, segment: 'Young'}
- {user: sam, age: 25, income: 45000, spend: 1200, segment: 'Young'}
- {user: sally, age: 29, income: 56000, spend: 1800, segment: 'Young'}
- {user: betty, age: 31, income: 60000, spend: 2000, segment: 'Young'}
# Mid Segment
- {user: tim, age: 34, income: 67000, spend: 2100, segment: 'Mid'}
- {user: mike, age: 38, income: 74000, spend: 2600, segment: 'Mid'}
- {user: lulu, age: 41, income: 79000, spend: 2800, segment: 'Mid'}
- {user: charlie, age: 44, income: 83000, spend: 3000, segment: 'Mid'}
# Senior Segment
- {user: romeo, age: 46, income: 87000, spend: 3100, segment: 'Senior'}
- {user: tango, age: 50, income: 95000, spend: 3700, segment: 'Senior'}
- {user: alpha, age: 55, income: 102000, spend: 4200, segment: 'Senior'}
- {user: foxtrot, age: 60, income: 110000, spend: 4800, segment: 'Senior'}
attributes:
user: { label: Who }
age: { label: Years Old }
income: { hidden: false, label: Income Level, type: number, options: {format: dollar, decimal: 0} }
spend: { hidden: false, label: Spend Amount, type: number, options: {format: dollar, decimal: 0} }
segment: { label: Segment Group }
output: testData
- print:
- transpose:
- print:
- transpose: {dataset: testData, id: user}
- print:
Explanation:
id; columns become rows with default column names (col0, col1, …).user column values as column headers.income formatted as dollars) carry over to the resulting rows.id values — transposed dataset may become very wide.extras.transposed flag can be used by downstream steps like table builders or visualization steps to correctly interpret the PDV.