Nodes/ComfyUI-Data-Analysis/Pandas Create From Dict Index List
ComfyUI Node

Pandas Create From Dict Index List

When your row labels actually mean something

By HowToSD·Created 2 years ago·Updated about a year ago· 23
Pandas Create From Dict Index List
  • data
  • index
  • DATAFRAME

Pandas Create From Dict Index List is the upgrade path from Pandas Create From Dict. Same idea - a Python dict becomes a DataFrame - except now you also supply the row index, so your rows get labels that mean something instead of a boring 0, 1, 2, 3. If you've ever loaded player stats and wanted the player names as the index rather than as a column you'd have to set later, this is the node that does it at creation time.

It takes two required inputs: data (PYDICT, the columns) and index (PYLIST, the row labels). Both come from the pack's text-to-python nodes - Py String To Dict for the dict and Py String To List for the index list. The output is a DATAFRAME with your index already attached.

A concrete example: a dict {"hits": [3600, 3771, 3000]} plus an index list ["Mays", "Aaron", "Musial"] gives you a one-column frame where the rows are named. Downstream, Pandas Loc Row Series and friends can then select rows by those labels, which is how the whole pack's selection model is designed to work.

How it behaves

The source is short, and one line in it is worth knowing about:

if not list:
    df = pd.DataFrame(data, index=list(range(value_length)))
else:
    df = pd.DataFrame(data, index=index)

That first branch is checking the Python built-in list type, which is always truthy - so it's dead code. In practice the node always uses the index list you give it. That means: if your index list's length doesn't match the number of rows in your dict, pandas raises a "length of values does not match length of index" error and your run fails. Don't count on it auto-generating an index for you; pass a correctly sized list. It's the one real gotcha and it's baked into the implementation, not the docs.

Wiring and install

PYDICT and PYLIST inputs render as text widgets, and the connection points live at the top-left corner of each field - the user's guide calls this out explicitly because everyone fumbles it. Drag toward the corner until the socket appears.

Installation is the pack-wide story:

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

or via ComfyUI Manager (search "Data analysis"), then restart. No GPU required, no models to download. When the dict and index both come from text you typed, this node is basically the "type your table with named rows" entry point for the whole pack.

CategoryData Analysis

Inputs (2)

NameTypeDefaultDescription
dataPYDICT
indexPYLIST

Outputs (1)

NameTypeDescription
DATAFRAMEDATAFRAME