code: def ranking(trials, group_by="order", key="best"):
      """Compute the ranking of some trial attribute.
  
      By default it will compute the ranking with respect to objectives at each time step across
      multiple experiments.
  
      Parameters
      ----------
      trials: DataFrame
          A dataframe of trials containing, at least, the columns 'best' and 'order'.
      group_by: str, optional
          The attribute to use to group trials for the ranking. By default it group trials
          by order (ex: all first trials across experiments.)
      key: str, optional
          The attribute to use for the ranking. Defaults to 'best' as returned by
          ``orion.analysis.regret``.
  
      Returns
      -------
      A copy of the original dataframe with a new column 'rank' for the rankings.
  
      """
      if trials.empty:
          return trials
  
      def rank(row):
          indices = row[key].argsort().to_numpy()
          ranks = numpy.empty_like(indices)
          ranks[indices] = numpy.arange(len(ranks))
          row["rank"] = ranks
          return row
  
      return trials.groupby(group_by, group_keys=False).apply(rank)
  
file_path: orion/src/orion/analysis/base.py
imports: import itertools
  from functools import reduce
  import numpy
  import pandas
  from sklearn.ensemble import AdaBoostRegressor, BaggingRegressor, ExtraTreesRegressor, GradientBoostingRegressor, RandomForestRegressor
  from orion.core.utils import format_trials
  from orion.core.worker.transformer import build_required_space
label_desc: Use image node_id 2 for calling a global function with example usage: ranking(trials, group_by, key) and returns: trials, trials, row