code: def convert_tables_to_dicts(
      dfs,
      row_indices: Sequence[int | str] | None = None,
      col_names: Sequence[str] | None = None,
      col_types: dict[str, dict[str, Any] | None] | None = None,
      col_groups: dict[str, Sequence[str]] | None = None,
      **kwargs,
  ) -> list[dict[str, Any]]:
      """
      Utility to join pandas tables, select rows, columns and generate groups.
      Will return a list of dictionaries, every dictionary maps to a row of data in tables.
  
      Args:
          dfs: data table in pandas Dataframe format. if providing a list of tables, will join them.
          row_indices: indices of the expected rows to load. it should be a list,
              every item can be a int number or a range `[start, end)` for the indices.
              for example: `row_indices=[[0, 100], 200, 201, 202, 300]`. if None,
              load all the rows in the file.
          col_names: names of the expected columns to load. if None, load all the columns.
          col_types: `type` and `default value` to convert the loaded columns, if None, use original data.
              it should be a dictionary, every item maps to an expected column, the `key` is the column
              name and the `value` is None or a dictionary to define the default value and data type.
              the supported keys in dictionary are: ["type", "default"], and note that the value of `default`
              should not be `None`. for example::
  
                  col_types = {
                      "subject_id": {"type": str},
                      "label": {"type": int, "default": 0},
                      "ehr_0": {"type": float, "default": 0.0},
                      "ehr_1": {"type": float, "default": 0.0},
                  }
  
          col_groups: args to group the loaded columns to generate a new column,
              it should be a dictionary, every item maps to a group, the `key` will
              be the new column name, the `value` is the names of columns to combine. for example:
              `col_groups={"ehr": [f"ehr_{i}" for i in range(10)], "meta": ["meta_1", "meta_2"]}`
          kwargs: additional arguments for `pandas.merge()` API to join tables.
  
      """
      df = reduce(
          lambda l, r: pd.merge(l, r, **kwargs), ensure_tuple(dfs)
      )
      # parse row indices
      rows: list[int | str] = []
      if row_indices is None:
          rows = slice(df.shape[0])  # type: ignore
      else:
          for i in row_indices:
              if isinstance(i, (tuple, list)):
                  if len(i) != 2:
                      raise ValueError(
                          "range of row indices must contain 2 values: start and end."
                      )
                  rows.extend(list(range(i[0], i[1])))
              else:
                  rows.append(i)
  
      # convert to a list of dictionaries corresponding to every row
      data_ = (
          df.loc[rows] if col_names is None else df.loc[rows, col_names]
      )
      if isinstance(col_types, dict):
          # fill default values for NaN
          defaults = {
              k: v["default"]
              for k, v in col_types.items()
              if v is not None and v.get("default") is not None
          }
          if defaults:
              data_ = data_.fillna(value=defaults)
          # convert data types
          types = {
              k: v["type"]
              for k, v in col_types.items()
              if v is not None and "type" in v
          }
          if types:
              data_ = data_.astype(dtype=types, copy=False)
      data: list[dict] = data_.to_dict(orient="records")
  
      # group columns to generate new column
      if col_groups is not None:
          groups: dict[str, list] = {}
          for name, cols in col_groups.items():
              groups[name] = df.loc[rows, cols].values
          # invert items of groups to every row of data
          data = [
              dict(d, **{k: v[i] for k, v in groups.items()})
              for i, d in enumerate(data)
          ]
  
      return data
  
imports: from __future__ import annotations
  import hashlib
  import json
  import logging
  import math
  import os
  import pickle
  import sys
  from collections import abc, defaultdict
  from collections.abc import Generator, Iterable, Mapping, Sequence, Sized
  from copy import deepcopy
  from functools import reduce
  from itertools import product, starmap, zip_longest
  from pathlib import PurePath
  from typing import Any
  import numpy
  import torch
  from torch.utils.data._utils.collate import default_collate
  from monai import config
  from monai.config.type_definitions import NdarrayOrTensor, NdarrayTensor, PathLike
  from monai.data.meta_obj import MetaObj
  from monai.utils import MAX_SEED, BlendMode, Method, NumpyPadMode, TraceKeys, convert_data_type, convert_to_dst_type, ensure_tuple, ensure_tuple_rep, ensure_tuple_size, fall_back_tuple, first, get_equivalent_dtype, issequenceiterable, look_up_option, optional_import, pytorch_after
label_desc: Use image node_id 35 for calling a global function with example usage: convert_tables_to_dicts(dfs, row_indices, col_names, col_types, col_groups) and returns: data