plydata.cat_tools.cat_drop

plydata.cat_tools.cat_drop(c, only=None)

Remove unused categories

Parameters
clist-like

Values that will make up the categorical.

onlylist-like (optional)

The categories to remove if they are empty. If not given, all unused categories are dropped.

Examples

>>> c = pd.Categorical(list('abcdd'), categories=list('bacdefg'))
>>> c
['a', 'b', 'c', 'd', 'd']
Categories (7, object): ['b', 'a', 'c', 'd', 'e', 'f', 'g']
>>> cat_remove_unused(c)
['a', 'b', 'c', 'd', 'd']
Categories (4, object): ['b', 'a', 'c', 'd']
>>> cat_remove_unused(c, only=['a', 'e', 'g'])
['a', 'b', 'c', 'd', 'd']
Categories (5, object): ['b', 'a', 'c', 'd', 'f']