plydata.cat_tools.cat_shift¶
-
plydata.cat_tools.
cat_shift
(c, n=1)[source]¶ Shift and wrap-around categories to the left or right
- Parameters
- clist-like
Values that will make up the categorical.
- n
int
Number of times to shift. If positive, shift to the left, if negative shift to the right. Default is 1.
- Returns
- out
categorical
Values
- out
Examples
>>> c = ['a', 'b', 'c', 'd', 'e'] >>> cat_shift(c) ['a', 'b', 'c', 'd', 'e'] Categories (5, object): ['b', 'c', 'd', 'e', 'a'] >>> cat_shift(c, 2) ['a', 'b', 'c', 'd', 'e'] Categories (5, object): ['c', 'd', 'e', 'a', 'b'] >>> cat_shift(c, -2) ['a', 'b', 'c', 'd', 'e'] Categories (5, object): ['d', 'e', 'a', 'b', 'c'] >>> cat_shift(pd.Categorical(c, ordered=True), -3) ['a', 'b', 'c', 'd', 'e'] Categories (5, object): ['c' < 'd' < 'e' < 'a' < 'b']