ComfyUI Node

Pandas Melt

The reshape that turns wide data into long data

By HowToSD·Created 2 years ago·Updated about a year ago· 23
Pandas Melt
  • dataframe
  • DATAFRAME
id_vars
value_vars
var_name
value_name
ignore_indextrue

Charts, groupby operations, and most plotting libraries want data in long format - one row per observation. Your spreadsheet, by contrast, almost certainly arrives in wide format - one row per subject, with repeated categories spread across columns. Pandas Melt is the node that converts between them: it "unpivots" wide columns down into key/value pairs. It's the data-reshaper you reach for right before a Seaborn plot from this same pack refuses to look right.

The pack is ComfyUI-Data-Analysis by Hide Inada (HowToSD), and this is one of its most genuinely useful nodes. The author ships a full worked example in the source docstring: a frozen-food price table with Pizza and Burger columns melts into a tidy Item / Price layout. Worth reading once, because melt's vocabulary - id_vars, value_vars - is the confusing part.

How it works

At its core it calls dataframe.melt(...). Every field is a comma-separated string, and the node converts them to lists (a single value works too):

  • id_vars - the columns that stay put, identifying each row (like Manufacturer).
  • value_vars - the columns to unpivot (like Pizza,Burger).
  • var_name - the name of the new column holding the old column names (defaults to variable if blank).
  • value_name - the name of the new column holding the values (defaults to value).
  • ignore_index - True (default) gives a fresh sequential index; False keeps and repeats the original one.

So the wide frozen-food table with Pizza and Burger columns becomes long rows: Aimee Italian Foods, Pizza, 10 and Aimee Italian Foods, Burger, 12. Same information, different shape - and immediately plottable.

The inputs that matter

All five fields above are required, but the two you'll actually think about are id_vars and value_vars. If you want to melt everything except the id columns, leave value_vars blank and the node melts all remaining columns. The var_name/value_name pair is cosmetic but worth setting - nobody wants columns called variable and value in their final dataset.

How to install it

Pack-wide install:

cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Data-Analysis.git
mv ComfyUI-Data-Analysis data-analysis
pip install -r requirements.txt

or ComfyUI Manager → search "Data analysis" → install → restart → reload. The pack's standard stack (pandas, matplotlib, seaborn, scipy, scikit-learn) comes along; no GPU, no models.

Common issues

  • It silently ignores a column - you typed a column name that isn't in value_vars, so it wasn't melted. The node splits on commas exactly; no comma, no list.
  • MultiIndex columns - not supported here (the source says so). Flatten your column index first.
  • The output looks "too long" - that's melt working. Long format is supposed to be longer; you've stacked the categories into rows.

Melt is the node that makes wide survey/spreadsheet data usable in ComfyUI, and this implementation is faithful to pandas - down to the exact same defaults. If you know df.melt() in a notebook, you know this node.

CategoryData Analysis

Inputs (6)

NameTypeDefaultDescription
dataframeDATAFRAME
id_varsSTRING
value_varsSTRING
var_nameSTRING
value_nameSTRING
ignore_indexBOOLEANtrue

Outputs (1)

NameTypeDescription
DATAFRAMEDATAFRAME