code: def _aggregate(y, aggfunc, weights):
      """Apply aggregation function by row.
  
      Parameters
      ----------
      y : pd.DataFrame
          Multivariate series to transform.
      aggfunc : str
          Aggregation function used for transformation.
      weights : list of floats
          Weights to apply in aggregation.
  
      Returns
      -------
      y_agg: pd.Series
          Transformed univariate series.
      """
      if weights is None:
          aggfunc = _check_aggfunc(aggfunc, weighted=False)
          y_agg = aggfunc(y, axis=1)
      else:
          aggfunc = _check_aggfunc(aggfunc, weighted=True)
          y_agg = aggfunc(y, axis=1, weights=np.array(weights))
  
      return pd.Series(y_agg, index=y.index)
  
imports: import numpy
  import pandas
  from scipy.stats import gmean
  from sklearn.pipeline import Pipeline
  from sktime.forecasting.base import ForecastingHorizon
  from sktime.forecasting.base._meta import _HeterogenousEnsembleForecaster
  from sktime.split import temporal_train_test_split
  from sktime.utils.stats import _weighted_geometric_mean, _weighted_max, _weighted_median, _weighted_min
  from sktime.utils.validation.forecasting import check_regressor
label_desc: Use image node_id 2 for calling a global function with example usage: _aggregate(y, aggfunc, weights) and returns: pd