Pandas Select Rows
Pandas Select Rows
- dataframe
- DATAFRAME
"Show me the rows where this is true" is the most common thing you'll do with data, and Pandas Select Rows is that, as a node. You type a condition into a string field - hits > 200, team == 'Yankees', year >= 2020 and hits > 150 - and the node keeps only the rows that satisfy it. It's the filter you reach for constantly: isolate a subgroup before plotting, drop bad records, scope an analysis to a slice of the data. If you're going to remember one node from this pack, honestly, this is a strong candidate.
It's from HowToSD/ComfyUI-Data-Analysis, under Data subset selection.
How it works
The node internally calls pandas' DataFrame.query(condition) - and that's the whole trick, because query is not arbitrary Python. It's pandas' own expression language, which means column names are referenced bare (no df["hits"] syntax) and string comparisons need quotes inside the condition: team == 'red'. Multiple conditions chain with and, or, and not. The query is evaluated per row, and the result is a new DataFrame containing only the matching rows, with the original index preserved.
Because query uses column names directly, a column with a space or a weird character needs backticks - `my column` > 5. And you cannot reference a Python variable inside the string; whatever you type is evaluated against the DataFrame's columns as literals.
Inputs and output
dataframe- the table to filter.condition- the query string, e.g.hits > 200 and year == 2021.
Output: a DATAFRAME of the matching rows. Wire it into plots, save nodes, or further analysis.
Installation
Standard pack install. 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. Deps: pandas, matplotlib, seaborn, scipy, scikit-learn, openpyxl, lxml - no GPU, no models.
The gotchas
Quoting is where beginners get burned: inside the condition, strings need single quotes (team == 'red'), and that lives inside a text field that doesn't care about your outer quoting, so it's just about getting the inner quotes right. Bad syntax raises an error rather than silently returning nothing, which is helpful. One more: query is for expressions on columns - if your filter depends on the row's position rather than its values, that's a different node (iloc-based). And if the condition returns an empty table, that's not a bug - it means no row matched, which is sometimes exactly the answer.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| dataframe | DATAFRAME | — | |
| condition | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| DATAFRAME | DATAFRAME | — |