Initializing playground…
← Back to roadmap

🔄 melt — Interactive Playground

Unpivot a DataFrame from wide format to long format — mirrors pandas.melt() / DataFrame.melt().
Edit any code block below and press ▶ Run (or Ctrl+Enter) to execute it live in your browser.

1 · Basic melt

Melt all value columns into a single variable / value pair.

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

2 · Preserve identifier columns

Use id_vars to keep columns as identifiers that are repeated for each melted row.

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

3 · Selective value columns

Use value_vars to specify which columns to unpivot.

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

4 · Multiple id columns

Pass an array to id_vars to use multiple identifier columns.

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

API Reference

Unpivot a DataFrame from wide to long format. Columns not specified as id_vars or value_vars are melted into variable / value pairs.

melt(df: DataFrame, options?: {
  id_vars?:    string | string[],   // columns to keep as identifiers
  value_vars?: string | string[],   // columns to unpivot (default: all non-id)
  var_name?:   string,              // name for the variable column (default: "variable")
  value_name?: string,              // name for the value column (default: "value")
}): DataFrame