code: def average(trials, group_by="order", key="best", return_var=False):
      """Compute the average of some trial attribute.
  
      By default it will compute the average objective 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 average. By default it group trials
          by order (ex: all first trials across experiments.)
      key: str, optional
          One attribute or a list of attributes split by ',' to average.
          Defaults to 'best' as returned by ``orion.analysis.regret``.
      return_var: bool, optional
          If True, and a column '{key}_var' where '{key}' is the value of the argument `key`.
          Defaults to False.
  
      Returns
      -------
      A dataframe with columns 'order', '{key}_mean' and '{key}_var'.
  
      """
      if trials.empty:
          return trials
  
      group = trials.groupby(group_by)
      means = []
      keys = [v.strip() for v in key.split(",")]
      for k in keys:
          mean = (
              group[k]
              .mean()
              .reset_index()
              .rename(columns={k: f"{k}_mean"})
          )
          if return_var:
              mean[f"{k}_var"] = group[k].var().reset_index()[k]
          means.append(mean)
  
      df_merged = reduce(pd.merge, means)
  
      return df_merged
  
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 1 for calling a global function with example usage: average(trials, group_by, key, return_var) and returns: df_merged, trials