code: def _merge_small_categories(
      df_cat: pd.DataFrame, col: str, hue: str, nb_cat_max: int
  ) -> pd.DataFrame:
      """
      Merges categories of column 'col' of df_cat into 'Other' category so that
      the number of categories is less than nb_cat_max.
      """
      df_cat_sum_hue = (
          df_cat.groupby([col]).agg({"count": "sum"}).reset_index()
      )
      list_cat_to_merge = df_cat_sum_hue.sort_values(
          "count", ascending=False
      )[col].to_list()[nb_cat_max - 1 :]
      df_cat_other = (
          df_cat.loc[df_cat[col].isin(list_cat_to_merge)]
          .groupby(hue, as_index=False)[["count", "Percent"]]
          .sum()
      )
      df_cat_other[col] = "Other"
      return pd.concat(
          [
              df_cat.loc[~df_cat[col].isin(list_cat_to_merge)],
              df_cat_other,
          ],
          axis=0,
      )
  
file_path: shapash/shapash/report/plots.py
imports: from typing import Union, Optional
  import pandas
  import numpy
  import seaborn
  import matplotlib.pyplot
  from matplotlib.colors import LinearSegmentedColormap
  from shapash.utils.utils import truncate_str
  from shapash.report.common import VarType
  from shapash.style.style_utils import get_pyplot_color, get_palette
label_desc: Use image node_id 4 for calling a global function with example usage: _merge_small_categories(df_cat, col, hue, nb_cat_max) and returns: pd