code: def transform_distribution_balance_measures(
      df: pd.DataFrame,
  ) -> Dict[str, Dict[str, float]]:
      """
      Transform the distribution balance measures df into a dictionary
      acceptable by the RAI dashboard.
  
      :param df: The distribution balance measures DataFrame.
      :type df: pd.DataFrame
      :return: A dictionary of distribution balance measures.
      :rtype: Dict[str, Dict[str, float]]
      """
      measures: Dict[str, Dict[str, float]] = {}
  
      try:
          rows: List[Any] = df.reset_index(drop=True).to_dict(
              orient="records"
          )
  
          # Transform { "FeatureName": "Col1", "MeasureA": 0.5, ... } to
          # { "Col1": { "BalanceMeasure": 0.5, ... } }
          # which allows us to treat FeatureNames as the keys of the dict
          for row in rows:
              feature_name: str = row.pop(Constants.FEATURE_NAME.value)
              measures[feature_name] = row
      except Exception as e:
          # Warning instead of error so that other measures can be computed
          warnings.warn(
              f"Failed to transform distribution measures due to {e!r}.",
          )
  
      return measures
  
file_path: responsible-ai-toolbox/responsibleai/responsibleai/databalanceanalysis/data_balance_utils.py
imports: import warnings
  from typing import Any, Dict, List
  import pandas
  from responsibleai.databalanceanalysis.constants import Constants
label_desc: Use image node_id 4 for calling a global function with example usage: transform_distribution_balance_measures(df) and returns: measures