def remove_unused_categories(self, inplace=False):
inplace = validate_bool_kwarg(inplace, '<STR_LIT>')<EOL>cat = self if inplace else self.copy()<EOL>idx, inv = np.unique(cat._codes, return_inverse=True)<EOL>if idx.size != <NUM_LIT:0> and idx[<NUM_LIT:0>] == -<NUM_LIT:1>:  <EOL><INDENT>idx, inv = idx[<NUM_LIT:1>:], inv - <NUM_LIT:1><EOL><DEDENT>new_categories = cat.dtype.categories.take(idx)<EOL>new_dtype = CategoricalDtype._from_fastpath(new_categories,<EOL>ordered=self.ordered)<EOL>cat._dtype = new_dtype<EOL>cat._codes = coerce_indexer_dtype(inv, new_dtype.categories)<EOL>if not inplace:<EOL><INDENT>return cat<EOL><DEDENT>
Remove categories which are not used.

Parameters
----------
inplace : bool, default False
   Whether or not to drop unused categories inplace or return a copy of
   this categorical with unused categories dropped.

Returns
-------
cat : Categorical with unused categories dropped or None if inplace.

See Also
--------
rename_categories
reorder_categories
add_categories
remove_categories
set_categories