Pandas Loc Row MultiIndex DataFrame
Picking rows when your index has two keys
- dataframe
- DATAFRAME
If you've been following the loc nodes in this pack, this is the one that handles the awkward case. A plain DataFrame has one row label per row. A MultiIndex DataFrame - the kind that falls out of groupby or pivot - has two or more labels stacked per row, like ("Aimee Italian Foods", "Pizza"). You can't select those with a single value, so Pandas Loc Row MultiIndex DataFrame exists to take your comma-separated labels, build the right tuple, and hand back a whole DataFrame row.
This is a real power-user corner of the pack, and it's also the one where beginners most often bounce off. The good news: the node does almost everything for you, including a partial-indexing feature that's easy to miss and genuinely useful.
How it works
The node splits your row_index string on commas, strips whitespace, and - if you've set row_index_type to int - casts each label to an integer. Then it builds a tuple and calls dataframe.loc[tuple].
The hidden trick is partial indexing. If you supply fewer labels than the index has levels, the node pads the rest with slice(None) - meaning "all of this level." So on a two-level index you can pass just the first level's label and get every row under it, as a DataFrame. And if loc happens to return a Series (which it does when exactly one row matches), the node converts it to a one-row DataFrame so the output type stays consistent.
The inputs that matter
dataframe- theDATAFRAMEwith the MultiIndex.row_index- comma-separated labels, e.g.Aimee Italian Foods,Pizza. Order follows your index levels.row_index_type-stringorint, applied to all the labels you typed. This is the sharp edge: the source explicitly notes that mixed data types within a MultiIndex aren't supported, so pick whichever matches your actual index.
Output is a DATAFRAME - always a DataFrame, even for a single row - so it feeds straight into whatever comes next in your pipeline.
How to install it
Same pack install as the rest:
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 via ComfyUI Manager (search "Data analysis"). Restart, reload, done. The usual heavy deps (pandas, matplotlib, seaborn, scipy, scikit-learn) come along, and no GPU is needed.
Common issues
KeyErroron a row you can see - type mismatch on the labels (index is int, you typed strings), or a label contains a comma. The comma is the separator, so a label with a comma in it can't be expressed here.- Mixed-type MultiIndex - not supported by design. Keep index levels all-strings or all-ints.
- You wanted the row as a Series, not a DataFrame - different node.
Pandas Loc Row Seriesgives you thePDSERIESflavor; this one is for when you need the result to stay tabular.
The one-liner mental model: for flat indexes use Pandas Loc Row Series, for stacked indexes reach here.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| dataframe | DATAFRAME | — | |
| row_index | STRING | — | |
| row_index_type | COMBO | 2 options: string, int |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| DATAFRAME | DATAFRAME | — |