polars melt for dataframe

Unpivot a DataFrame from wide to long format.

Signature

> polars melt {flags}

Flags

  • --columns, -c {table}: column names for melting
  • --values, -v {table}: column names used as value columns
  • --variable-name, -r {string}: optional name for variable column
  • --value-name, -l {string}: optional name for value column

Input/output types:

inputoutput
anyany

Examples

melt dataframe

> [[a b c d]; [x 1 4 a] [y 2 5 b] [z 3 6 c]] | polars into-df | polars melt -c [b c] -v [a d]
╭───┬───┬───┬──────────┬───────╮
 # │ b │ c │ variable │ value │
├───┼───┼───┼──────────┼───────┤
 0 1 4 a x
 1 2 5 a y
 2 3 6 a z
 3 1 4 d a
 4 2 5 d b
 5 3 6 d c
╰───┴───┴───┴──────────┴───────╯