code: def _get_best_row_for_scalarized_objective(
      df: pd.DataFrame,
      objective: ScalarizedObjective,
  ) -> pd.Series:
      df = df.copy()
      # First, add a weight column, setting 0.0 if the metric is not part
      # of the objective
      metric_to_weight = {
          m.name: objective.weights[i]
          for i, m in enumerate(objective.metrics)
      }
      df["weight"] = df["metric_name"].apply(
          lambda x: metric_to_weight.get(x) or 0.0
      )
      # Now, calculate the weighted linear combination via groupby,
      # filtering out NaN for missing data
      df["weighted_mean"] = df["mean"] * df["weight"]
      groupby_df = (
          df[["arm_name", "trial_index", "weighted_mean"]]
          .groupby(["arm_name", "trial_index"], as_index=False)
          .sum(min_count=1)
          .dropna()
      )
      if groupby_df.empty:
          raise ValueError(
              "No data has been logged for scalarized objective."
          )
      return (
          groupby_df.loc[groupby_df["weighted_mean"].idxmin()]
          if objective.minimize
          else groupby_df.loc[groupby_df["weighted_mean"].idxmax()]
      )
  
imports: from collections import OrderedDict
  from functools import reduce
  from logging import Logger
  from typing import Dict, Iterable, List, Optional, Tuple, Type
  import pandas
  import torch
  from ax.core.base_trial import TrialStatus
  from ax.core.batch_trial import BatchTrial
  from ax.core.data import Data
  from ax.core.experiment import Experiment
  from ax.core.generator_run import GeneratorRun
  from ax.core.objective import MultiObjective, Objective, ScalarizedObjective
  from ax.core.observation import Observation
  from ax.core.optimization_config import MultiObjectiveOptimizationConfig, OptimizationConfig
  from ax.core.outcome_constraint import ObjectiveThreshold, OutcomeConstraint
  from ax.core.trial import Trial
  from ax.core.types import ComparisonOp, TModelPredictArm, TParameterization
  from ax.exceptions.core import UnsupportedError, UserInputError
  from ax.modelbridge.base import ModelBridge
  from ax.modelbridge.cross_validation import assess_model_fit, compute_diagnostics, cross_validate
  from ax.modelbridge.generation_strategy import GenerationStrategy
  from ax.modelbridge.modelbridge_utils import observed_pareto_frontier, predicted_pareto_frontier
  from ax.modelbridge.registry import get_model_from_generator_run, ModelRegistryBase, Models
  from ax.modelbridge.torch import TorchModelBridge
  from ax.modelbridge.transforms.utils import derelativize_optimization_config_with_raw_status_quo
  from ax.plot.pareto_utils import get_tensor_converter_model
  from ax.utils.common.logger import get_logger
  from ax.utils.common.typeutils import checked_cast, not_none
  from numpy import NaN
  from torch import Tensor
label_desc: Use image node_id 12 for calling a global function with example usage: _get_best_row_for_scalarized_objective(df, objective) and returns: unknown