code: def rebalance_by_categorical(
      dataset: pd.DataFrame,
      categ_column: str,
      max_lines_by_categ: int = None,
      seed: int = 1,
  ) -> pd.DataFrame:
      """
      Resample dataset so that the result contains the same number of lines per category in  categ_column.
  
      Parameters
      ----------
      dataset: pandas.DataFrame
          A Pandas' DataFrame with an categ_column column
  
      categ_column: str
          The name of the categorical column
  
      max_lines_by_categ: int (default None)
          The maximum number of lines by category. If None it will be set to the number of lines for the smallest category
  
      seed: int (default 1)
          Random state for consistency.
  
      Returns
      ----------
      rebalanced_dataset : pandas.DataFrame
          A dataset with fewer lines than dataset, but with the same number of lines per category in categ_column
      """
  
      categs = dataset[categ_column].value_counts().to_dict()
      max_lines_by_categ = (
          max_lines_by_categ
          if max_lines_by_categ
          else min(categs.values())
      )
  
      return pd.concat(
          [
              (
                  dataset.loc[dataset[categ_column] == categ, :].sample(
                      max_lines_by_categ, random_state=seed
                  )
              )
              for categ in list(categs.keys())
          ]
      )
  
label_desc: Use image node_id 1 for calling a global function with example usage: rebalance_by_categorical(dataset, categ_column, max_lines_by_categ, seed) and returns: pd