plydata.cat_tools.cat_relevel

plydata.cat_tools.cat_relevel(c, *args, to=0)

Reorder categories explicitly

Parameters
clist-like

Values that will make up the categorical.

*argstuple

Categories to reorder. Any categories not mentioned will be left in existing order.

toint or inf

Position where to place the categories. inf, puts them at the end (highest value).

Returns
outcategorical

Values

Examples

>>> c = ['a', 'b', 'c', 'd', 'e']
>>> cat_move(c, 'e', 'b')
['a', 'b', 'c', 'd', 'e']
Categories (5, object): ['e', 'b', 'a', 'c', 'd']
>>> cat_move(c, 'c', to=np.inf)
['a', 'b', 'c', 'd', 'e']
Categories (5, object): ['a', 'b', 'd', 'e', 'c']
>>> cat_move(pd.Categorical(c, ordered=True), 'a', 'c', 'e', to=1)
['a', 'b', 'c', 'd', 'e']
Categories (5, object): ['b' < 'a' < 'c' < 'e' < 'd']