Pandas Replace Advanced
Pandas Replace Advanced
- dataframe
- DATAFRAME
When your dirty data is dirty in known ways, you don't need regex - you need a lookup table. Pandas Replace Advanced is exactly that: type a dictionary of exact value → replacement, and every cell matching a key gets rewritten. {"cat": "dog", "mountain": "ocean"}. No patterns, no escaping, no surprises across all columns - the node matches whole cell values, string or number, and swaps them. It's the safer sibling of Pandas Replace, and for cleaning up categorical columns (inconsistent spellings, mixed-case variants, coded values that need human names) it's the one I'd actually reach for.
It's part of HowToSD/ComfyUI-Data-Analysis, the pandas-in-ComfyUI pack, and lives in its Data cleansing category next to the regex-based Replace.
How it works
The replacement_dict field is a multiline string parsed with Python's ast.literal_eval - so again, Python dict syntax, not JSON-with-extras. The node validates that it's a dict and that every key and value is a string or a number (no nested structures), then calls pandas' DataFrame.replace(to_replace=d). Matching is by exact value: a key of "cat" only rewrites cells whose entire value is "cat". That's the crucial difference from the regex node - partial matches are ignored, so "cat" won't touch "catalog".
Because keys can be numbers too, this is also the node for fixing numeric codes - {0: "no", 1: "yes"} on a binary column works fine.
Inputs
dataframe- the table.replacement_dict- the mapping, multiline STRING. Default{}.
Output: the cleaned DATAFRAME.
Installation
Standard pack install, same as every node here. ComfyUI Manager: search Data analysis, install ComfyUI-Data-Analysis. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Data-Analysis.git
mv ComfyUI-Data-Analysis data-analysis # examples need this folder name
pip install -r requirements.txt
Restart, reload. Usual deps - pandas, matplotlib, seaborn, scipy, scikit-learn, openpyxl, lxml - no GPU, no model downloads.
The trap: it's exact-match only
That's simultaneously its strength and its limit. If your data has values like "cat " with trailing spaces, exact matching won't catch them - those need the regex node (or a strip-first pass). The error messages here are genuinely good: wrong format, non-dict input, or bad value types all raise clear errors instead of silently doing nothing, which is more than most nodes in this pack offer. And a nice property: keys that don't appear in the data are simply ignored - so you can keep a canonical cleaning dictionary in the workflow and let it stay valid even when columns change.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| dataframe | DATAFRAME | — | |
| replacement_dict | STRING | {} | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| DATAFRAME | DATAFRAME | — |