plydata.cat_tools.cat_shuffle

plydata.cat_tools.cat_shuffle(c, random_state=None)[source]

Reverse order of categories

Parameters
clist-like

Values that will make up the categorical.

random_stateint or RandomState, optional

Seed or Random number generator to use. If None, then numpy global generator numpy.random is used.

Returns
outcategorical

Values

Examples

>>> np.random.seed(123)
>>> c = ['a', 'b', 'c', 'd', 'e']
>>> cat_shuffle(c)
['a', 'b', 'c', 'd', 'e']
Categories (5, object): ['b', 'd', 'e', 'a', 'c']
>>> cat_shuffle(pd.Categorical(c, ordered=True), 321)
['a', 'b', 'c', 'd', 'e']
Categories (5, object): ['d' < 'b' < 'a' < 'c' < 'e']