class_docstr: Accessor object for categorical properties of the Series values.
  
  Examples
  --------
  >>> s = ps.Series(list("abbccc"), dtype="category")
  >>> s  # doctest: +SKIP
  0    a
  1    b
  2    b
  3    c
  4    c
  5    c
  dtype: category
  Categories (3, object): ['a', 'b', 'c']
  
  >>> s.cat.categories
  Index(['a', 'b', 'c'], dtype='object')
  
  >>> s.cat.codes
  0    0
  1    1
  2    1
  3    2
  4    2
  5    2
  dtype: int8
class_docstr_tok: ["Accessor","object","for","categorical","properties","of","the","Series","values",".","Examples","--","--","--","--",">",">",">","s","=","ps.Series","(","list","(","``","abbccc","''",")",",","dtype=","''","category","''",")",">",">",">","s","#","doctest",":","+SKIP","0","a","1","b","2","b","3","c","4","c","5","c","dtype",":","category","Categories","(","3",",","object",")",":","[","'","a","'",",","'","b","'",",","'","c","'","]",">",">",">","s.cat.categories","Index","(","[","'","a","'",",","'","b","'",",","'","c","'","]",",","dtype='object","'",")",">",">",">","s.cat.codes","0","0","1","1","2","1","3","2","4","2","5","2","dtype",":","int8"]
docstr: Remove categories which are not used.
  
  Returns
  -------
  cat : Series
      Categorical with unused categories dropped
  
  See Also
  --------
  rename_categories : Rename categories.
  reorder_categories : Reorder categories.
  add_categories : Add new categories.
  remove_categories : Remove the specified categories.
  set_categories : Set the categories to the specified ones.
  
  Examples
  --------
  >>> s = ps.Series(pd.Categorical(list("abbccc"), categories=['a', 'b', 'c', 'd']))
  >>> s  # doctest: +SKIP
  0    a
  1    b
  2    b
  3    c
  4    c
  5    c
  dtype: category
  Categories (4, object): ['a', 'b', 'c', 'd']
  
  >>> s.cat.remove_unused_categories()  # doctest: +SKIP
  0    a
  1    b
  2    b
  3    c
  4    c
  5    c
  dtype: category
  Categories (3, object): ['a', 'b', 'c']
docstr_tok: ["Remove","categories","which","are","not","used",".","Returns","--","--","--","-","cat",":","Series","Categorical","with","unused","categories","dropped","See","Also","--","--","--","--","rename_categories",":","Rename","categories",".","reorder_categories",":","Reorder","categories",".","add_categories",":","Add","new","categories",".","remove_categories",":","Remove","the","specified","categories",".","set_categories",":","Set","the","categories","to","the","specified","ones",".","Examples","--","--","--","--",">",">",">","s","=","ps.Series","(","pd.Categorical","(","list","(","``","abbccc","''",")",",","categories=","[","'","a","'",",","'","b","'",",","'","c","'",",","'d","'","]",")",")",">",">",">","s","#","doctest",":","+SKIP","0","a","1","b","2","b","3","c","4","c","5","c","dtype",":","category","Categories","(","4",",","object",")",":","[","'","a","'",",","'","b","'",",","'","c","'",",","'d","'","]",">",">",">","s.cat.remove_unused_categories","(",")","#","doctest",":","+SKIP","0","a","1","b","2","b","3","c","4","c","5","c","dtype",":","category","Categories","(","3",",","object",")",":","[","'","a","'",",","'","b","'",",","'","c","'","]"]
code: def remove_unused_categories(self) -> Optional["ps.Series"]:
      """
      Remove categories which are not used.
  
      Returns
      -------
      cat : Series
          Categorical with unused categories dropped
  
      See Also
      --------
      rename_categories : Rename categories.
      reorder_categories : Reorder categories.
      add_categories : Add new categories.
      remove_categories : Remove the specified categories.
      set_categories : Set the categories to the specified ones.
  
      Examples
      --------
      >>> s = ps.Series(pd.Categorical(list("abbccc"), categories=['a', 'b', 'c', 'd']))
      >>> s  # doctest: +SKIP
      0    a
      1    b
      2    b
      3    c
      4    c
      5    c
      dtype: category
      Categories (4, object): ['a', 'b', 'c', 'd']
  
      >>> s.cat.remove_unused_categories()  # doctest: +SKIP
      0    a
      1    b
      2    b
      3    c
      4    c
      5    c
      dtype: category
      Categories (3, object): ['a', 'b', 'c']
      """
      categories = set(self._data.drop_duplicates()._to_pandas())
      removals = [
          cat for cat in self.categories if cat not in categories
      ]
      categories = [cat for cat in removals if cat is not None]  # type: ignore[assignment]
      if len(categories) == 0:
          return self._data.copy()
      else:
          dtype = CategoricalDtype(
              [cat for cat in self.categories if cat not in categories],
              ordered=self.ordered,
          )
          return self._data.astype(dtype)
  
imports: from typing import Any, Callable, List, Optional, Union, TYPE_CHECKING, cast
  import pandas
  from pandas.api.types import CategoricalDtype, is_dict_like, is_list_like
  from pyspark.pandas.internal import InternalField
  from pyspark.pandas.data_type_ops.categorical_ops import _to_cat
  from pyspark.sql import functions
  from pyspark.sql.types import StructField
label_desc: Use image node_id 12 for calling the CategoricalAccessor obj's underlying member method code with example usage: obj.remove_unused_categories() and returns: self, self