Pandas Group By
The 'group by year, sum the hits' node the whole pack is built around
- dataframe
- DATAFRAME
Pandas Group By is the centerpiece of the ComfyUI-Data-Analysis pack - literally. The README's flagship tutorial asks "Which MLB player had the most hits per year?", and this node is how you answer it: group the batting table by year, sum the hits, then pick the max. If you install this pack for exactly one reason, this is the reason. It's the split-apply-combine operation - group rows that share a value, then apply an aggregation to each group - turned into three fields on a node.
How it works
You give it a DataFrame, a column_name to group by, and an aggregation. The node runs dataframe.groupby(column_name).agg() under the hood, and the enum offers six aggregations: sum, mean, count, std, min, max. Pick sum and you get, for each group, the total of every numeric column. Pick mean and you get averages. The result's index becomes the group values themselves - group by yearID and the output rows are the years - which is exactly what makes downstream sorting and plotting clean.
A couple of real-world notes. First, the input field is literally spelled aggragate_function in the schema - yes, with the "grag" typo - so when you see that in the node's info panel, that's the aggregation selector, not a different thing. Second, this is a single-column group by only. The pack's user guide shows multi-column aggregation using multiple Group By nodes in sequence, so don't hunt for a comma-separated multi-key option; chain nodes instead.
Third, the group column ends up as the index, not as a regular column. That matters if you feed the result to a plotting node and the group labels don't show up where you expect. If you need it back as a column, run Pandas Reset Index-style cleanup after - the pack has nodes for that.
The baseball workflow
Concretely: load Batting.csv with Pandas Load CSV, set column_name to the year column, aggragate_function to sum, and out the other end comes each year's totals - hits summed across every player. From there it's sort and pick the top row. That's the whole tutorial, and it's a great template for your own "group something, aggregate something" questions.
Inputs and outputs
- dataframe (required,
DATAFRAME) - the frame to group. - column_name (required,
STRING) - the column whose values define the groups. - aggragate_function (required, enum) -
sum,mean,count,std,min,max. - DATAFRAME output - the aggregated table, grouped values as index.
Installing it
Standard pack install. ComfyUI Manager → search "Data analysis" → install ComfyUI-Data-Analysis → restart → reload the browser. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Data-Analysis
mv ComfyUI-Data-Analysis data-analysis
pip install -r data-analysis/requirements.txt
Requirements: pandas, matplotlib, seaborn, scipy, scikit-learn, openpyxl, lxml. No GPU, no model downloads. If the node errors, nine times out of ten it's a column-name mismatch - group by a column that doesn't exist (or isn't in the frame after a transformation) and pandas throws a KeyError. Check your column names with Pandas Columns first.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| dataframe | DATAFRAME | — | |
| column_name | STRING | — | |
| aggragate_function | COMBO | 6 options: sum, mean, count, std, min, max |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| DATAFRAME | DATAFRAME | — |