code: def transform_to_nixtla_df(df, settings_dict, exog_vars=[]):
      """Transform dataframes into the specific format required by StatsForecast.
  
      Nixtla packages require dataframes to have the following columns:
          unique_id -> the grouping column. If multiple groups are specified then
          we join them into one name using a / char.
          ds -> the date series
          y -> the target variable for prediction
  
      You can optionally include exogenous regressors after these three columns, but
      they must be numeric.
      """
      nixtla_df = df.copy()
  
      # Resample every group
      freq = settings_dict["frequency"]
      resampled_df = pd.DataFrame(columns=nixtla_df.columns)
      if settings_dict["group_by"] and settings_dict["group_by"] != [
          "__group_by"
      ]:
          for group, groupdf in nixtla_df.groupby(
              by=settings_dict["group_by"]
          ):
              groupdf.index = pd.to_datetime(
                  groupdf.pop(settings_dict["order_by"])
              )
              resampled_groupdf = pd.DataFrame(
                  groupdf[settings_dict["target"]].resample(freq).mean()
              )
              for k, v in zip(settings_dict["group_by"], group):
                  resampled_groupdf[k] = v
              resampled_groupdf = resampled_groupdf.reset_index()
              resampled_df = pd.concat(
                  [resampled_df, resampled_groupdf]
              )
          nixtla_df = resampled_df
  
      # Transform group columns into single unique_id column
      if len(settings_dict["group_by"]) > 1:
          for col in settings_dict["group_by"]:
              nixtla_df[col] = nixtla_df[col].astype(str)
          nixtla_df["unique_id"] = nixtla_df[
              settings_dict["group_by"]
          ].agg("/".join, axis=1)
          group_col = "ignore this"
      else:
          group_col = settings_dict["group_by"][0]
  
      # Rename columns to statsforecast names
      nixtla_df = nixtla_df.rename(
          {
              settings_dict["target"]: "y",
              settings_dict["order_by"]: "ds",
              group_col: "unique_id",
          },
          axis=1,
      )
  
      if "unique_id" not in nixtla_df.columns:
          # add to dataframe as it is expected by statsforecast
          nixtla_df["unique_id"] = "1"
  
      columns_to_keep = ["unique_id", "ds", "y"] + exog_vars
      nixtla_df["ds"] = pd.to_datetime(nixtla_df["ds"])
      return nixtla_df[columns_to_keep]
  
file_path: mindsdb/mindsdb/integrations/utilities/time_series_utils.py
imports: import numpy
  import pandas
  from pandas.tseries.frequencies import to_offset
  from sklearn.metrics import r2_score
  from mindsdb.utilities import log
label_desc: Use image node_id 1 for calling a global function with example usage: transform_to_nixtla_df(df, settings_dict, exog_vars) and returns: nixtla_df