unpivot

fnDataFrame unpivot(DataFrame df, string[] valueColumns, string[] indexColumns = [], string variableName = "variable", string valueName = "value")

Unpivots the frame: the valueColumns stack into variableName/valueName pairs (value-column outer, input row inner), the indexColumns repeat per stacked column, and every other column is dropped - visible in the signature, Polars 2.0 parity (ADR-2026-10-24-20).

The stacked value dtype keeps identical dtypes and otherwise joins in the numeric lattice of ADR-2026-10-24-19 (all-integer INT64 exact widening, any float FLOAT64, UINT64 meeting a signed integer FLOAT64 with the approximation disclosed); any other mix rejects with an error naming the pair - no silent stringification. Nulls stack as nulls. Zero rows or zero value columns produce zero rows with the variable/value (and index) columns present.

Parameters

dfthe frame to reshape
valueColumnsthe columns to stack (in output order)
indexColumnsthe columns to repeat per stacked column
variableNamethe stacked column-name column
valueNamethe stacked values column

Returns

the unpivoted frame: the index columns, variableName,

valueName.

Throws

DataFrameException for absent columns or duplicate output

names.

Example:

auto df = DataFrame([
   Series("i", [1, 2]),
   Series("a", [10L, 20]),
   Series("b", [30L, 40]),
]);
auto tall = unpivot(df, ["a", "b"], ["i"]);
assert(tall.columns() == ["i", "variable", "value"]);
assert(tall["variable"].toArray!string() == ["a", "a", "b", "b"]);
assert(tall["value"].toArray!long() == [10, 20, 30, 40]);