Manage categorical data — mirrors pandas.Categorical and
Series.cat.
Edit any code block below and press ▶ Run
(or Ctrl+Enter) to execute it live in your browser.
Access series.cat.categories for the sorted unique labels and
series.cat.codes for the integer encoding.
Missing values (null) are not counted as categories and get a
code of -1.
Use addCategories() to register new labels (without needing them in the
data yet) and removeCategories() to drop labels (values become null).
removeUnusedCategories() drops any categories not present in the data.
Pass an object mapping old names → new names, or an array of replacement names.
setCategories() replaces the entire category list (values not in the new
list become null). reorderCategories() changes the order without adding
or removing.
valueCounts() returns a Series with the count of each category
(zero for unused ones).
asOrdered() marks a categorical as ordered (enabling comparisons).
The order is determined by the categories array index.
The .cat accessor is available on any Series containing string or
categorical data. It provides pandas-compatible category management methods.
series.cat.categories // Index of sorted unique labels
series.cat.codes // Series<number> of integer codes (-1 for null)
series.cat.nCategories // number of distinct categories
series.cat.ordered // boolean — is the categorical ordered?
series.cat.addCategories(newCats: string[]): Series
series.cat.removeCategories(cats: string[]): Series
series.cat.removeUnusedCategories(): Series
series.cat.renameCategories(mapping: Record | string[]): Series
series.cat.setCategories(cats: string[]): Series
series.cat.reorderCategories(cats: string[], ordered?: boolean): Series
series.cat.asOrdered(): Series
series.cat.asUnordered(): Series
series.cat.valueCounts(): Series<number>