Ciaren

Bin column

Bin column — binColumn

Bucket a numeric column into labeled bins (a new column).

Use cases

  • Turn ages or amounts into bands (0–18, 19–35, …).
  • Create quantile buckets (quartiles, deciles) for segmentation.

What it does

Reads a numeric column and writes a new text column whose values are the bin labels. equalwidth makes bins of equal numeric span; quantile makes bins with roughly equal row counts.

Before
nametotal_spent
Grace500
Margaret250
Ada100
Linus15
4 rows · 2 cols
Bin column (column=total_spent, bins=3, method=quantile, labels=[Bronze,Silver,Gold])
After
nametotal_spenttiernew
Grace500Gold
Margaret250Silver
Ada100Bronze
Linus15Bronze
4 rows · 3 cols

Configuration

Config keyTypeRequiredDescription
columnstringYesNumeric column to bin
new_columnstringYesName of the new bin column
binsintNoNumber of bins (≥ 2, default 4)
methodstringNoequalwidth (default) or quantile
labelsstring[]NoCustom labels (one per bin)

Generated Python code

df_2 = df_1.assign(amount_band=pd.cut(df_1['amount'], bins=4).astype('string'))

Tips & common mistakes

  • equalwidth vs quantile: equal-width splits the value range into equal spans (uneven counts); quantile splits into equal-sized groups (uneven spans).
  • Custom labels must match the bin count (one label per bin).
  • The result is a text/category column — feed it into Group by + aggregate to count per band.

See also