class_docstr: Initializes the Approximate Inference class.
  
  Parameters
  ----------
  model: Instance of pgmpy.models.BayesianNetwork or pgmpy.models.DynamicBayesianNetwork
  
  Examples
  --------
  >>> from pgmpy.utils import get_example_model
  >>> model = get_example_model('alarm')
  >>> infer = ApproxInference(model)
docstr: Takes a groupby dataframe and converts it into a pgmpy.factors.discrete.DiscreteFactor object.
code: def _get_factor_from_df(df, state_names):
      """
      Takes a groupby dataframe and converts it into a pgmpy.factors.discrete.DiscreteFactor object.
      """
      variables = list(df.index.names)
      if len(variables) == 1:
          df_index = state_names[variables[0]]
      else:
          df_index = itertools.product(
              *[state_names[var] for var in variables]
          )
      # state_names = {var: list(df.index.unique(var)) for var in variables}
      cardinality = [len(state_names[var]) for var in variables]
      return DiscreteFactor(
          variables=variables,
          cardinality=cardinality,
          values=df.reindex(df_index).fillna(0).values,
          state_names=state_names,
      )
  
file_path: pgmpy/pgmpy/inference/ApproxInference.py
imports: import itertools
  from pgmpy.factors.discrete import DiscreteFactor
  from pgmpy.models import BayesianNetwork, DynamicBayesianNetwork
label_desc: Use image node_id 2 for calling the ApproxInference obj's underlying member method code with example usage: obj._get_factor_from_df(df, state_names) and returns: DiscreteFactor