Initializing playground…
← Back to roadmap

Categorical Ops

Standalone categorical utility functions that complement the Series.cat accessor. Mirrors pd.Categorical.from_codes, set operations on categories, frequency helpers, and cross-tabulation.

catFromCodes(codes, categories, opts?)

Construct a categorical Series from integer codes (0-based) and a categories array. Code -1 maps to null (missing). Mirrors pd.Categorical.from_codes.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

Category set operations

catUnionCategories, catIntersectCategories, catDiffCategories, and catEqualCategories let you combine or compare the category sets of two Series.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

catSortByFreq(series, opts?)

Reorder categories by their frequency in the data (most frequent first by default). Mirrors s.cat.reorder_categories(s.value_counts().index).

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

catToOrdinal(series, order)

Create an ordered categorical from a Series using order to define both the category set and their rank. Values not in order become null.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

catFreqTable(series)

Return a plain Record<string, number> of counts per category. Zero-frequency categories are included.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

catCrossTab(a, b, opts?)

Cross-tabulation of two categorical Series. Rows = a's categories, columns = b's categories, cells = co-occurrence counts. Supports margins and normalization.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent

catRecode(series, mapping)

Rename categories via an object map or a transform function. Unmapped categories are left unchanged.

TypeScript
Click ▶ Run to execute
Ctrl+Enter to run · Tab to indent