ComfyUI Node

Pandas Sort

Sort a DataFrame by a column, ascending or not

By HowToSD·Created 2 years ago·Updated about a year ago· 23
Pandas Sort
  • dataframe
  • DATAFRAME
column_name
ascendingtrue

Ordering rows is one of those operations you don't think about until you need the top of a leaderboard - and then it's everything. Pandas Sort reorders the rows of a DataFrame by a column you name, with a toggle for ascending/descending. It's the pack's answer to "give me the biggest hitters first," which is literally the use case its author's baseball tutorial drives toward: load stats, sort by hits, read the top row.

It's a transformation node with zero surprises. In a typical data-analysis workflow you'd place it after a load or a filter and before a display or plot node - Pandas SortPandas HeadPandas Show DataFrame, or straight into a bar chart so the tallest bar is also the first one.

How it works

The implementation is a one-liner over pandas: dataframe.sort_values(by=column_name, ascending=ascending). That means the semantics are pandas semantics - it's a stable sort, it returns a new sorted frame (your original stays untouched), and missing values sort last by default regardless of direction. There's no multi-column sorting here; one column, one direction.

Inputs and outputs

Two inputs actually matter:

  • dataframe (DATAFRAME) - the frame to reorder.
  • column_name (STRING, default empty) - the exact column label to sort by. This is where people get burned: it's not a dropdown, and pandas is picky. H won't match hits.
  • ascending (BOOLEAN, default true) - uncheck it for descending, which is what you want for "most hits first."

Output: a single sorted DATAFRAME.

Installing this pack

This node ships in ComfyUI-Data-Analysis by Hide Inada (HowToSD). CPU-only, no GPU, no model downloads - but the pack needs its Python stack, which stock ComfyUI doesn't ship: pandas, matplotlib, seaborn, scipy, scikit-learn, openpyxl, lxml.

ComfyUI Manager: Manager → Custom Node Manager → search "Data analysis" → install ComfyUI-Data-Analysis → restart ComfyUI and refresh the browser. Manager installs the deps for you.

Git clone:

cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Data-Analysis.git
mv ComfyUI-Data-Analysis data-analysis   # example workflows depend on this folder name
pip install -r data-analysis/requirements.txt

Restart ComfyUI after installing.

Troubleshooting

  • "Column not found" style errors. The column name must match exactly, including case and any spaces. If you're not sure what the columns are called, attach Pandas Columns (or Pandas Show DataFrame) upstream and read the labels first.
  • Nothing seems sorted. Check you actually re-ran the graph - sort is a transform, and downstream nodes only update when the workflow runs.
  • Mixed types in the column. Sorting a column that's part string, part number sorts lexically and looks wrong. Clean the column type upstream first.
CategoryData Analysis

Inputs (3)

NameTypeDefaultDescription
dataframeDATAFRAME
column_nameSTRING
ascendingBOOLEANtrue

Outputs (1)

NameTypeDescription
DATAFRAMEDATAFRAME