code: def metric_group_max(df, metric_names=None):
      """Find the step which achieves the highest mean value for a group of metrics."""
      # Use METRIC_NAMES defined at the top as default
      metric_names = metric_names or METRIC_NAMES
      group_to_metrics = collections.defaultdict(set)
      for metric in metric_names.values():
          group_to_metrics[metric.group].add(metric.name)
      group_df = pd.DataFrame()
      for group, metrics in group_to_metrics.items():
          if not all(m in df for m in metrics):
              continue
          group_df[group] = df[list(metrics)].mean(axis=1)
      # Need to replace nan with large negative value for idxmax
      group_max_step = group_df.fillna(-1e9).idxmax(axis=0)
      metric_max = pd.Series()
      metric_max_step = pd.Series()
      for group_name, max_step in group_max_step.items():
          for metric in group_to_metrics[group_name]:
              metric_max[metric] = df[metric][max_step]
              metric_max_step[metric] = max_step
      metric_max = metric_max.reindex(df.columns)
      metric_max_step = metric_max_step.reindex(df.columns)
      return metric_max, metric_max_step
  
file_path: text-to-text-transfer-transformer/t5/evaluation/eval_utils.py
imports: import collections
  import os
  from absl import logging
  import numpy
  import pandas
  import tensorflow.compat.v1
  import tensorflow_datasets
label_desc: Use image node_id 6 for calling a global function with example usage: metric_group_max(df, metric_names) and returns: metric_max,  metric_max_step