code: def get_stock_group(
      stock_group_field_df,
      bench_stock_weight_df,
      group_method,
      group_n=None,
  ):
      if group_method == "category":
          # use the value of the benchmark as the category
          return stock_group_field_df
      elif group_method == "bins":
          assert group_n is not None
          # place the values into `group_n` fields.
          # Each bin corresponds to a category.
          new_stock_group_df = stock_group_field_df.copy().loc[
              bench_stock_weight_df.index.min() : bench_stock_weight_df.index.max()
          ]
          for idx, row in (~bench_stock_weight_df.isna()).iterrows():
              bench_values = stock_group_field_df.loc[
                  idx, row[row].index
              ]
              new_stock_group_df.loc[idx] = get_daily_bin_group(
                  bench_values,
                  stock_group_field_df.loc[idx],
                  group_n=group_n,
              )
          return new_stock_group_df
  
file_path: qlib/qlib/backtest/profit_attribution.py
imports: import datetime
  from pathlib import Path
  import numpy
  import pandas
  from ..config import C
  from ..data import D
  from .position import Position
label_desc: Use image node_id 6 for calling a global function with example usage: get_stock_group(stock_group_field_df, bench_stock_weight_df, group_method, group_n) and returns: stock_group_field_df, new_stock_group_df