π€ Dataset Map Column
Add a column to every row β constants, copies, or a row index, all in the graph
- dataset
- dataset
The most common thing you do to a table in real data work isn't filtering - it's adding a column. A stable ID so you can track a row after a shuffle. A flag you want on every record. A copy of another field under a new name because the downstream tool insists on its own key. π€ Dataset Map Column is that operation as a node: it adds (or replaces) one column across every row, with the value computed three ways.
How it works
Under the hood it's datasets map - the Swiss-army transform - but you never write the mapping function. The three operation choices cover the cases people actually hit:
constant- every row gets the literal text you type invalue. Handy for stamping a version tag, a source label, or a fixed prompt prefix onto a batch before export.copy column-valuenames an existing column whose values get copied intocolumn. Great when you need the same data under a different key and don't want to rearrange the original.row index- each row gets its 0-based position as an integer. This is the sleeper feature. Give every review anidbefore you shuffle, and you can still trace samples back to their original position - which is exactly the bookkeeping a training-set builder wants.
column defaults to new_column; set it to a name that already exists and the node replaces that column, dropping the old values first (even across types, the tooltip notes). Output is a new HUGGINGFACE_DATASET with the column added, so it slots into any chain - Map Column β Filter β To Data List is a classic.
One thing the node is not: a free-form Python mapper. If you need text.upper() + column B, this won't do it - the operations are deliberately the three boring, safe ones. That's a feature for a graph environment where a node shouldn't be able to execute arbitrary code per row.
Inputs, briefly
column- name to add or replace (defaultnew_column).operation-constant,copy column, orrow index.value- literal forconstant, source column name forcopy column; ignored forrow index.
Unlike several nodes in this pack, Map Column works on fully-loaded and streaming datasets, so you can stamp IDs onto a lazy IterableDataset without forcing a full download.
Installing it
Part of the ComfyUI-huggingface_dataset pack (StableLlama). ComfyUI-Manager β search "Hugging Face dataset", or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-huggingface_dataset
pip install -r requirements.txt
Restart ComfyUI. The only runtime dependency is datasets, installed automatically by Manager.
Gotchas worth knowing
The replacement behavior can surprise you: if column already exists and you pick constant, you're overwriting that column for every row, not appending. Check that you're not clobbering data you need. And if you name the source column itself as the target for copy column (copying text into text), the node still works - it copies from the original before the replace - but it's a no-op you probably didn't intend. Row-index values start at 0, matching Python and datasets, so don't expect 1-based numbering.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| dataset | HUGGINGFACE_DATASET | Dataset whose column to add or replace (from the π€ Dataset Loader or another dataset node). | |
| column | STRING | new_column | Name of the column to add or replace. |
| operation | COMBO | constant | How to compute the value: constant, copy column, or row index. |
| value | STRING | Literal value for 'constant', or the source column name for 'copy column'. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| dataset | HUGGINGFACE_DATASET | The dataset with the added or replaced column. |