Pandas Iloc Rows DataFrame
Select rows by a list of positions, not a range
- dataframe
- DATAFRAME
Sometimes you don't want a contiguous block of rows - you want row 0, row 3, and row 7, in exactly that order. PandasIlocRowsDataFrame does that: give it a DataFrame and a list of integer positions, and it returns a new DataFrame containing just those rows. This is the pack's "grab a custom set of rows" node, and it's the one that makes things like sampling a subset or reordering rows a two-second task.
It comes from HowToSD's ComfyUI-Data-Analysis pack, Hide Inada's pandas/matplotlib/seaborn wrapper set that turns ComfyUI into a visual data tool. No GPU, no models - pure pandas.
How it works
The mechanism is dataframe.iloc[row_int_pos_list], where the list comes from a JSON string. That's the interesting part: row_int_pos_list_json isn't a widget where you pick rows - it's a STRING you fill with a JSON array. So you type [0, 3, 7], and the node parses it with json.loads and selects those positions. The author's user guide suggests building that list with the pack's CDA JSON Create node when you want to construct it dynamically instead of hardcoding.
.iloc is position-based, which means the numbers are physical row indices, 0-counted. Order in the list is honored - [3, 0] returns row 3 first, then row 0. The result is a fresh DataFrame, and the original is left untouched.
The inputs that matter
- dataframe - the source table.
- row_int_pos_list_json - the JSON array of positions, like
[0, 3, 7]. This is the input to get right: malformed JSON fails the run, and an out-of-range position raises anIndexError.
Output is a single DATAFRAME containing just the selected rows, in the order you listed them.
Installing it
Standard for this pack. ComfyUI Manager: search "ComfyUI-Data-Analysis", install, restart. Dependencies - pandas, matplotlib, seaborn, scipy, scikit-learn, openpyxl, lxml - are handled by Manager. Manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Data-Analysis.git
pip install -r requirements.txt
Then rename the clone to data-analysis so the example workflows resolve their files (the README is insistent about this). And the license: custom non-commercial - personal/academic OK, commercial use needs written permission from the author.
Gotchas
The JSON input is the whole personality of this node. [0, 3, 7] works; 0, 3, 7 (no brackets) does not, and neither does a trailing comma. If you're generating the list from another node, keep it strict JSON. Note this is the position-based selection, so it uses .iloc semantics - if your rows have meaningful labels and you want to select by label, look for the loc-based row nodes instead. For a simple contiguous run, the slice node (Pandas Iloc Rows Slice DataFrame) is less typing; this one earns its keep when the row set is irregular.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| dataframe | DATAFRAME | — | |
| row_int_pos_list_json | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| DATAFRAME | DATAFRAME | — |