Skip to main content

Transpose

Use the Transpose gem to reshape your dataset by unpivoting columns—perfect for preparing time series data, feeding models, or simplifying analysis. This transformation:

  • Takes data in wide format (multiple columns for similar data)
  • Converts it to long format (stacked rows with a single column for names and one for values)

Parameters

ParameterDescription
Key ColumnsColumns that act as identifiers for each row.
Data ColumnsColumns (wide format) that you want to transform into a single column (long format).

Example

Imagine you have sales data for different products, with each quarter's sales stored in its own column—this is known as wide format. Before modeling seasonal trends or doing time series analysis, it's often helpful to convert this into long format, where each row represents a single observation.

ProductQ1Q2Q3Q4
A100150130170
B90120110160

To configure a Transpose gem for this table:

  1. Identify and enter the key columns. In the example above, the Product column is the key column.
  2. Select the data columns to unpivot. In the example above, all of the quarter columns (Q1, Q2, etc.) are your data columns.
  3. Save and run the gem.

Result

After the transformation:

  • The quarter names (Q1, Q2, etc.) will move into a new Name column.
  • The corresponding sales values will be stored in a Value column.
ProductNameValue
AQ1100
AQ2150
AQ3130
AQ4170
BQ190
BQ2120
BQ3110
BQ4160

This makes your data easier to analyze over time, since each row now represents one product's sales for a specific quarter.