ComfyUI Node

Pandas Cos

Element-wise cosine — for when your data is actually an angle

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

The pack has a full set of math transforms - Pandas Sin, Pandas Tan, Pandas Log, Pandas Exp - and Pandas Cos is the cosine member: it applies the cosine function to every numeric cell in the DataFrame and returns a new frame of the same shape. It's a niche node, but the moment your data represents an angle or a cycle, it's exactly what you want.

How it works

First it coerces every cell with pd.to_numeric(errors='coerce'), so non-numeric junk becomes NaN instead of crashing - same coerce-to-NaN philosophy as Pandas As Float. Then it applies numpy.cos element-wise. The output is a same-shaped DataFrame where each value is the cosine of the original (in radians, because numpy always does radians - a classic trap if you're thinking in degrees).

And a note on expectations: this is the trig cosine (a point on the unit circle), not "cosine similarity." If you came here hoping to compare two rows' similarity, that's not this node - this is purely a per-cell math transform.

Inputs and outputs

  • dataframe - the frame to transform (DATAFRAME)
  • Output: a DATAFRAME with the cosine of every numeric cell, non-numeric cells as NaN

When you'd reach for it

Periodic or angular data, basically. Phase angles from a signal; seasonal/cyclical data you want to decompose; anything in degrees or radians you're projecting onto the unit circle. It's also handy in a data-pipeline where you want to pre-transform a feature before feeding it to a plot or a correlation. If you're doing data science inside ComfyUI (and that's precisely what this pack is for), the trig family rounds out the toolset even if you only touch it occasionally.

Installing it

Ships with ComfyUI-Data-Analysis (Hide Inada / HowToSD.com). Manager: search Data Analysis → install → restart. Or:

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

No GPU needed; pandas and numpy come with the requirements install.

Gotchas

Radians, radians, radians - a value of 90 comes out as cos(90 rad) ≈ -0.45, which looks wrong until you remember numpy doesn't care about your degrees. Convert with a scalar math node if you need degree-based trig. And remember non-numeric cells silently become NaN: if your "cosine" column comes back full of missing values, the source column wasn't numeric, so run Pandas As Float first.

CategoryData Analysis

Inputs (1)

NameTypeDefaultDescription
dataframeDATAFRAME

Outputs (1)

NameTypeDescription
DATAFRAMEDATAFRAME