code: def tabular_cpd_to_pd(tab_cpd: TabularCPD) -> pd.DataFrame:
      """
      Converts a pgmpy TabularCPD to a Pandas dataframe
  
      Args:
          tab_cpd: Tabular conditional probability distribution (CPD)
  
      Returns:
          Corresponding Pandas dataframe
      """
      node_states = tab_cpd.state_names
      iterables = [
          sorted(node_states[var]) for var in tab_cpd.variables[1:]
      ]
      cols = [""]
  
      if iterables:
          cols = pd.MultiIndex.from_product(
              iterables, names=tab_cpd.variables[1:]
          )
  
      tab_df = pd.DataFrame(
          tab_cpd.values.reshape(
              len(node_states[tab_cpd.variable]),
              max(1, len(cols)),
          )
      )
      tab_df[tab_cpd.variable] = sorted(node_states[tab_cpd.variable])
      tab_df.set_index([tab_cpd.variable], inplace=True)
      tab_df.columns = cols
      return tab_df
  
imports: from typing import List
  import pandas
  from pgmpy.factors import factor_product
  from pgmpy.factors.discrete import TabularCPD
label_desc: Use image node_id 2 for calling a global function with example usage: tabular_cpd_to_pd(tab_cpd) and returns: tab_df