API/BUG: awkward syntax to add categories to a Categorical · Issue #9927 · pandas-dev/pandas (original) (raw)
In [147]: s = pd.Categorical(list('aabbcd'))
In [148]: s2 = list('aabbcdefg')
In [149]: s
Out[149]:
[a, a, b, b, c, d]
Categories (4, object): [a, b, c, d]
In [150]: s.add_categories(s.categories.sym_diff(Index(s2)).tolist())
Out[150]:
[a, a, b, b, c, d]
Categories (7, object): [a, b, c, d, e, f, g]
s.add_categories(s2, take_new=True)