code: def transform_dataframe(
      df: pd.DataFrame,
      transformer,
      fit: bool = False,
      inverse_transform: bool = False,
  ) -> pd.DataFrame:
      """
      Transform raw values of pandas DataFrame with a scikit-learn alike
      transformer, preprocessor or ColumnTransformer. `inverse_transform` is not
      available when using ColumnTransformers.
  
      Parameters
      ----------
      df : pandas DataFrame
          DataFrame to be transformed.
      transformer : scikit-learn alike transformer, preprocessor or ColumnTransformer.
          scikit-learn alike transformer, preprocessor or ColumnTransformer.
      fit : bool, default `False`
          Train the transformer before applying it.
      inverse_transform : bool, default `False`
          Transform back the data to the original representation. This is not available
          when using transformers of class scikit-learn ColumnTransformers.
  
      Returns
      -------
      df_transformed : pandas DataFrame
          Transformed DataFrame.
  
      """
  
      if not isinstance(df, pd.DataFrame):
          raise TypeError(
              f"`df` argument must be a pandas DataFrame. Got {type(df)}"
          )
  
      if transformer is None:
          return df
  
      if inverse_transform and isinstance(
          transformer, ColumnTransformer
      ):
          raise Exception(
              "`inverse_transform` is not available when using ColumnTransformers."
          )
  
      if not inverse_transform:
          if fit:
              values_transformed = transformer.fit_transform(df)
          else:
              values_transformed = transformer.transform(df)
      else:
          values_transformed = transformer.inverse_transform(df)
  
      if hasattr(values_transformed, "toarray"):
          # If the returned values are in sparse matrix format, it is converted to dense
          values_transformed = values_transformed.toarray()
  
      if hasattr(transformer, "get_feature_names_out"):
          feature_names_out = transformer.get_feature_names_out()
      elif hasattr(transformer, "categories_"):
          feature_names_out = transformer.categories_
      else:
          feature_names_out = df.columns
  
      df_transformed = pd.DataFrame(
          data=values_transformed,
          index=df.index,
          columns=feature_names_out,
      )
  
      return df_transformed
  
imports: from typing import Union, Any, Optional, Tuple, Callable
  import warnings
  import importlib
  import joblib
  import numpy
  import pandas
  import sklearn
  import sklearn.pipeline
  import sklearn.linear_model
  from sklearn.compose import ColumnTransformer
  from sklearn.exceptions import NotFittedError
  import inspect
  from copy import deepcopy
  import skforecast
  from ..exceptions import MissingValuesExogWarning
  from ..exceptions import DataTypeWarning
  from ..exceptions import IgnoredArgumentWarning
  from ..exceptions import SkforecastVersionWarning
label_desc: Use image node_id 19 for calling a global function with example usage: transform_dataframe(df, transformer, fit, inverse_transform) and returns: df_transformed, df