plydata.cat_tools.cat_unify¶
-
plydata.cat_tools.
cat_unify
(cs, categories=None)[source]¶ Unify (union of all) the categories in a list of categoricals
- Parameters
- cslist-like
Categoricals
- categorieslist-like
Extra categories to apply to very categorical.
Examples
>>> c1 = pd.Categorical(['a', 'b'], categories=list('abc')) >>> c2 = pd.Categorical(['d', 'e'], categories=list('edf')) >>> c1_new, c2_new = cat_unify([c1, c2]) >>> c1_new ['a', 'b'] Categories (6, object): ['a', 'b', 'c', 'e', 'd', 'f'] >>> c2_new ['d', 'e'] Categories (6, object): ['a', 'b', 'c', 'e', 'd', 'f'] >>> c1_new, c2_new = cat_unify([c1, c2], categories=['z', 'y']) >>> c1_new ['a', 'b'] Categories (8, object): ['a', 'b', 'c', 'e', 'd', 'f', 'z', 'y'] >>> c2_new ['d', 'e'] Categories (8, object): ['a', 'b', 'c', 'e', 'd', 'f', 'z', 'y']