code: def prepare_fg_from_dataframe_or_file(
      dataframe_or_path: Union[str, Path, pandas.DataFrame],
      feature_group_name: str,
      role: str = None,
      region: str = None,
      session=None,
      record_id: str = "record_id",
      event_id: str = "data_as_of_date",
      verbose: bool = False,
      **kwargs,
  ) -> FeatureGroup:
      """Prepares a dataframe to create a :class:`sagemaker.feature_store.feature_group.FeatureGroup`
  
      Description:
          Function to prepare a :class:`pandas.DataFrame` read from a path to a csv file or pass it
          directly to create a :class:`sagemaker.feature_store.feature_group.FeatureGroup`.
          The path to the file needs proper dtypes, feature names and mandatory features (record_id,
          event_id).
          It needs the :class:`sagemaker.session.Session` linked to a role
          or the region and/or role used to work with Feature Stores (it uses the module
          `sagemaker.feature_store.feature_utils.get_session_from_role`
          to get the session).
          If record_id or event_id are not specified it will create ones
          by default with the names 'record_id' and 'data_as_of_date'.
  
      Args:
          feature_group_name (str): feature group name
          dataframe_or_path (str, Path, pandas.DataFrame) : pandas.DataFrame or path to the data
          verbose (bool)           : True for displaying messages, False for silent method.
          record_id (str, 'record_id'): (Optional) Feature identifier of the rows. If specified each
                                      value of that feature has to be unique. If not specified or
                                      record_id='record_id', then it will create a new feature from
                                      the index of the pandas.DataFrame.
          event_id (str)           : (Optional) Feature with the time of the creation of data rows.
                                      If not specified it will create one with the current time
                                      called `data_as_of_date`
          role (str)               : role used to get the session.
          region (str)             : region used to get the session.
          session (str): session of SageMaker used to work with the feature store
          **kwargs (object): key arguments used for the method pandas.read_csv to be able to
                      have a better tuning on data. For more info read:
                      https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html
  
      Returns:
          :class:`sagemaker.feature_store.feature_group.FeatureGroup`:
              FG prepared with all the methods and definitions properly defined
      """
  
      logger.setLevel(logging.WARNING)
      if verbose:
          logger.setLevel(logging.INFO)
  
      if isinstance(dataframe_or_path, DataFrame):
          data = dataframe_or_path
      elif isinstance(dataframe_or_path, str):
          kwargs.pop("filepath_or_buffer", None)
          data = read_csv(
              filepath_or_buffer=dataframe_or_path, **kwargs
          )
      else:
          exc = Exception(
              str(
                  f"Invalid type {type(dataframe_or_path)} for "
                  "argument dataframe_or_path. \nParameter must be"
                  " of type pandas.DataFrame or string"
              )
          )
          logger.exception(exc)
          raise exc
  
      # Formatting cols
      data = _format_column_names(data=data)
      data = _cast_object_to_string(data_frame=data)
  
      if record_id == "record_id" and record_id not in data.columns:
          data[record_id] = data.index
  
      lg_uniq = len(data[record_id].unique())
      lg_id = len(data[record_id])
  
      if lg_id != lg_uniq:
          exc = Exception(
              str(
                  f"Record identifier {record_id} have {abs(lg_id - lg_uniq)} "
                  "duplicated rows. \nRecord identifier must be unique"
                  " in each row."
              )
          )
          logger.exception(exc)
          raise exc
  
      if event_id not in data.columns:
          import time
  
          current_time_sec = int(round(time.time()))
          data[event_id] = Series(
              [current_time_sec] * lg_id, dtype="float64"
          )
  
      if session is not None:
          sagemaker_session = session
      elif role is not None and region is not None:
          sagemaker_session = get_session_from_role(region=region)
      else:
          exc = Exception(
              "Argument Session or role and region must be specified."
          )
          logger.exception(exc)
          raise exc
  
      feature_group = FeatureGroup(
          name=feature_group_name, sagemaker_session=sagemaker_session
      )
  
      feature_group.load_feature_definitions(data_frame=data)
  
      return feature_group
  
file_path: sagemaker-python-sdk/src/sagemaker/feature_store/feature_utils.py
imports: from __future__ import absolute_import
  import re
  import logging
  from typing import Union
  from pathlib import Path
  import pandas
  import boto3
  from pandas import DataFrame, Series, read_csv
  from sagemaker.feature_store.feature_group import FeatureGroup
  from sagemaker.session import Session
label_desc: Use image node_id 5 for calling a global function with example usage: prepare_fg_from_dataframe_or_file(dataframe_or_path, feature_group_name, role, region, session, record_id, event_id, verbose) and returns: feature_group