code: def _groupby_new_state(index, outputs, decisions):
      
      output_map = {o: i for i, o in enumerate(outputs)}
      groups = pd.Series(index).groupby([output_map[d] for d in decisions])
      results = [(outputs[i], pd.Index(sub_group.values)) for i, sub_group in groups]
      selected_outputs = [o for o, _ in results]
      for output in outputs:
          if output not in selected_outputs:
              results.append((output, pd.Index([])))
      return results
docs: Groups the simulants in the index by their new output state.
  
      Parameters
      ----------
      index : iterable of ints
          An iterable of integer labels for the simulants.
      outputs : iterable
          A list of possible output states.
      decisions : `pandas.Series`
          A series containing the name of the next state for each simulant in the index.
  
      Returns
      -------
      iterable of 2-tuples
          The first item in each tuple is the name of an output state and the second item
          is a `pandas.Index` representing the simulants to transition into that state.