code: def get_clamped_value_counts(
      value_counts: pd.Series, max_categories_incl_other: int
  ) -> pd.Series:
      # Returns a Series of a maximum length, where overflowing rows are
      # put into a "Others" category (index = OTHERS_GROUPED)
      # IMPORTANT: assuming value_counts is ALREADY SORTED
      if len(value_counts) <= max_categories_incl_other:
          categories_shown_as_is = len(value_counts)
      else:
          categories_shown_as_is = max_categories_incl_other - 1
  
      # Fix for #10
      # clamped_series = pd.Series(value_counts[0:categories_shown_as_is])
      clamped_series = pd.Series(
          value_counts.head(categories_shown_as_is)
      )
  
      # Fix for #10
      num_in_tail = len(value_counts) - categories_shown_as_is
      # categories_in_other = value_counts[categories_shown_as_is:]
      categories_in_other = value_counts.tail(num_in_tail)
  
      if len(categories_in_other) > 0:
          total_in_other = sum(categories_in_other)
          if clamped_series.index.dtype.name == "category":
              # need to create categorical index
              clamped_series.index = (
                  clamped_series.index.add_categories([OTHERS_GROUPED])
              )
              other_series = pd.Series(
                  [total_in_other],
                  index=pd.CategoricalIndex(
                      [OTHERS_GROUPED], categories=clamped_series.index
                  ),
              )
  
          else:
              other_series = pd.Series(
                  [total_in_other], index=[OTHERS_GROUPED]
              )
  
          # UPDATE: series.append is deprecated!
          clamped_series = pd.concat([clamped_series, other_series])
          # clamped_series = clamped_series.append(other_series, ignore_index=False)
          # assert(clamped_series.equals(clamped_seriesOLD))
      return clamped_series
  
imports: import pandas
  from sweetviz.sv_types import OTHERS_GROUPED
label_desc: Use image node_id 1 for calling a global function with example usage: get_clamped_value_counts(value_counts, max_categories_incl_other) and returns: clamped_series