Initializing playground…
← Back to roadmap

↕ lreshape — Interactive Playground

Reshape wide-format data to long format using named column groups — mirrors pandas.lreshape().
Edit any code block below and press ▶ Run (or Ctrl+Enter) to execute it live in your browser.

1 · Basic lreshape

Stack two wide columns (v1, v2) into a single long column v, repeating the id column for each block.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

2 · Multiple groups

Reshape with multiple output columns simultaneously. Each output column is fed from a separate list of input columns.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

3 · dropna option

By default rows where any value column is null/NaN are dropped. Pass dropna: false to keep them.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

4 · Real-world: survey scores

Stack multiple rounds of survey scores into a long-format table.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

API Reference

Reshape wide-format data to long format by explicitly naming which input columns map to each output column.

lreshape(
  data: DataFrame,
  groups: Record<string, string[]>,  // { outputCol: [inputCol1, inputCol2, ...] }
  options?: {
    dropna?: boolean,  // drop rows with null/NaN values (default: true)
  }
): DataFrame

All input columns not mentioned in groups become identity (id) columns and are repeated for each block. All group lists must have the same length k; the result has nRows × k rows (before applying dropna).