value column and on value.
pivot
DataFrame pivot(DataFrame df, string[] index, string on, string[] values,
PivotAgg agg = PivotAgg.NONE)Pivots the frame: the distinct values of on become output columns (first-appearance order), the distinct index tuples become output rows (first-appearance order), and the cells hold the values aggregated per (index tuple, on value) (ADR-2026-10-24-20).
A single value column names each output column by the rendered on-value (the CSV cell renderers: decimal integers, shortest- round-trip floats, true/false, strict temporals, null); several value columns name {value}_{on} and run value-outer, on-inner. Duplicate cells error under the default NONE (naming the key and the count); missing cells take the aggregate's empty-set value (SUM/COUNT 0, FIRST/LAST/MIN/MAX/MEAN null). Null keys group (the grouping semantics). The output shape - index tuples x value columns x on values - is discovered before any cell is written; O(I.V.D) growth is the caller's to judge.
Parameters
df | the frame to reshape |
index | the row-key columns (empty: one aggregate row) |
on | the column whose distinct values become columns |
values | the cell columns (one or more) |
agg | the duplicate-cell policy |
Returns
Throws
duplicate cells under NONE, or a generated name colliding with an index column (or another generated name).
Example:
auto df = DataFrame([
Series("idx", ["a", "a", "b"]),
Series("on", ["x", "y", "x"]),
Series("v", [1L, 2, 3]),
]);
auto wide = pivot(df, ["idx"], "on", ["v"]);
assert(wide.columns() == ["idx", "x", "y"]);
assert(wide["x"].toArray!long() == [1, 3]);
assert(wide["y"].toNullableArray!long()[1].isNull);