code: def _targets_to_df(targets):
      # type: (List[TargetExplanation]) -> pd.DataFrame
      if targets and not isinstance(targets[0], TargetExplanation):
          raise ValueError(
              "Only lists of TargetExplanation are supported"
          )
      columns = ["target", "feature", "weight", "std", "value"]
      df_data = {f: [] for f in columns}  # type: Dict[str, List[Any]]
      for target in targets:
          assert target.feature_weights is not None
          for fw in chain(
              target.feature_weights.pos,
              reversed(target.feature_weights.neg),
          ):
              df_data["target"].append(target.target)
              df_data["feature"].append(fw.feature)
              df_data["weight"].append(fw.weight)
              df_data["std"].append(fw.std)
              df_data["value"].append(fw.value)
      for optional_field in ["std", "value"]:
          if all(x is None for x in df_data[optional_field]):
              df_data.pop(optional_field)
              columns.remove(optional_field)
      return pd.DataFrame(df_data, columns=columns)
  
file_path: eli5/eli5/formatters/as_dataframe.py
imports: from itertools import chain
  from typing import Any, Dict, List, Optional
  import warnings
  import pandas
  import eli5
  from eli5.base import Explanation, FeatureImportances, TargetExplanation, TransitionFeatureWeights
  from eli5.base_utils import singledispatch
label_desc: Use image node_id 9 for calling a global function with example usage: _targets_to_df(targets) and returns: pd