code: def states_to_df(
      node_states: Dict[AnyStr, Union[list, Set]]
  ) -> pd.DataFrame:
      """
      Return a dataframe containing all node states for all nodes.
      Used for fitting node states of an BN
  
      Args:
          node_states: Dictionary of node states
  
      Returns:
          Dataframe representing all node states
      """
      nodes = node_states.keys()
      max_card = max(len(el) for el in node_states.values())
      df = pd.DataFrame(np.zeros([max_card, len(nodes)]), columns=nodes)
  
      for node in nodes:
          values = list(node_states[node])
          df.loc[:, node] = (values * (1 + max_card // len(values)))[
              :max_card
          ]
  
      return df
  
imports: from typing import AnyStr, Dict, List, Set, Union
  import numpy
  import pandas
label_desc: Use image node_id 2 for calling a global function with example usage: states_to_df(node_states) and returns: df