Nodes/ComfyUI-Data-Analysis/Pandas Iloc Rows Slice DataFrame
ComfyUI Node

Pandas Iloc Rows Slice DataFrame

Slice a run of rows out of a DataFrame

By HowToSD·Created 2 years ago·Updated about a year ago· 23
Pandas Iloc Rows Slice DataFrame
  • dataframe
  • DATAFRAME
start_row0
end_row0

PandasIlocRowsSliceDataFrame is the "gimme rows 5 through 20" node. You give it a DataFrame, a start row, and an end row, and it returns a new DataFrame holding just that contiguous block. It's the simplest row-selection node in the pack and the one you'll reach for constantly once you're slicing tables to focus on a subset.

It ships in HowToSD's ComfyUI-Data-Analysis pack - Hide Inada's set of pandas, matplotlib, and seaborn wrappers that puts data analysis into ComfyUI's node graph. No GPU, no models, just pandas.

How it works

The call is dataframe.iloc[start_row:end_row]. Two details matter more than anything else:

  • Start is inclusive, end is exclusive. start_row=5, end_row=20 gives you rows 5 through 19 - twenty rows total. This is the classic off-by-one spot where beginners get a table with one row too many or too few. The author's docstring spells it out, but it's the kind of thing you still trip on.
  • It's position-based. .iloc counts physical rows from 0, ignoring whatever the index labels say. So the 10th row in the file is position 9.

The result is a brand-new DataFrame - the original is not modified, unlike the pack's cell-editing nodes.

The inputs that matter

  • dataframe - the source.
  • start_row - first row to include, inclusive. Default 0.
  • end_row - first row to stop before, exclusive. Default 0, which means an empty slice if you forget to set it - a silent "nothing came out" that confuses people more than an error would.

Output is a single DATAFRAME with the sliced rows.

Installing it

Same as the rest of the pack. ComfyUI Manager: search "ComfyUI-Data-Analysis", install, restart - it installs pandas, matplotlib, seaborn, scipy, scikit-learn, openpyxl, and lxml for you. Or clone:

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

Rename the cloned folder to data-analysis so the example workflows find their files. License note, once, since it applies pack-wide: custom non-commercial license - personal and academic use is allowed, commercial use requires the author's written permission.

Gotchas

The exclusive end is the trap - double-check your boundary rows. Negative values are allowed by the widget (min is -1), and pandas' slicing treats a negative end as counting from the end, so start=0, end=-1 grabs everything but the last row. That's handy when you know it, confusing when you don't. Also note both defaults are 0, so an unedited node returns an empty DataFrame rather than failing - the silent case is the one that eats your time. For irregular row sets (rows 0, 3, 7), use Pandas Iloc Rows DataFrame instead; this node is strictly for contiguous runs.

CategoryData Analysis

Inputs (3)

NameTypeDefaultDescription
dataframeDATAFRAME
start_rowINT0-1–2147483648
end_rowINT0-1–2147483648

Outputs (1)

NameTypeDescription
DATAFRAMEDATAFRAME