code: def plots_as_dataframes(
      plots: Iterable[PlotsForSlice],
      *,  # Keyword only args below.
      include_empty_columns: bool = False,
  ) -> PlotsDataFrames:
      """Read and deserialize the PlotsForSlice records as Pandas DataFrame.
  
      To load confusion_matrix_at_thresholds:
        df = plots_as_dataframes(tfma.load_plots(eval_path))
  
      For example, if the input plots_for_slice proto looks like this:
            slice_key {
               single_slice_keys {
                 column: "age"
                 float_value: 38.0
               }
             }
             plot_keys_and_values {
               key {}
               value {
                 confusion_matrix_at_thresholds {
                   matrices {
                     threshold: 0.5
                     false_negatives: 10
                     true_negatives: 10
                     false_positives: 10
                     true_positives: 10
                     precision: 0.9
                     recall: 0.8
                   }
                   matrices {
                     threshold: 0.5
                     false_negatives: 10
                     true_negatives: 10
                     false_positives: 10
                     true_positives: 10
                     precision: 0.9
                     recall: 0.8
                   }
                 }
               }
             }
  
      The corresponding output table will look like this:
  
      |                         plot_data |            plot_keys |          slices |
      | threshold | false_negatives | ... |              is_diff | ... |       age |
      |----------:|----------------:|----:|:---------------------| ... |:----------|
      |       0.5 |              10 | ... |                False | ... |        38 |
      |       0.5 |              10 | ... |                False | ... |        38 |
      # pylint: enable=line-too-long
  
      One typical use of this DataFrame table is to re-organize it in the form of
      slices vs. plots table.
      E.g., for single model single output:
        result.pivot(index='slice', columns='name', values='plot_data').
      This only works when there is one unique value as the pivot values.
      Otherewise, a user needs to specify more columns or indices to make sure that
      the metric value is unique per column and per index.
      E.g., for single model and multiple outputs:
        result.pivot(index='slice', columns=['output_name', 'name'],
                     values='plot_data').
  
      Args:
        plots: a path to the evaluation directory or an iterable of PlotsForSlice
          proto.
        include_empty_columns: include a column if its value is not empty (None) in
          corresponding field in the MetricKey.
  
      Returns:
        A DataFrame with the following columns if the value is not None:
        * slice_str: the string representation of the slice.
          E.g., "age: 10; sex: male".
        * <slice_feature_column>: feature columns derived from
          tfma.proto.metrics_for_slice_pb2.SliceKey. There are multiple feature
          columns if there is any feature-cross, e.g., slice.featureA and
          slice.featureB if there is FeatureA and FeatureB cross.
        * recursively flattened items in metric_key: name, model_name, output_name,
          is_diff, example_weighted, flattened sub_key (class_id, k, top_k),
          flattened aggregation_type (micro_average, macro_average,
          weighted_macro_average).
        * multiple columns of plot_values: plot_value specified by plot_type
          and flattened to its leaf primitives. E.g., there will be columns
          false_negatives, false_positives, true_negatives, true_positives,
          precision, recall when plot_type is `confusion_matrix_at_thresholds`.
      """
      dfs = _to_dataframes(
          plots,
          column_prefixes=_plot_columns,
          include_empty_columns=include_empty_columns,
      )
      return PlotsDataFrames(**dfs)
  
imports: import collections
  import dataclasses
  import itertools
  from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Union
  import numpy
  import pandas
  from tensorflow_model_analysis.proto import metrics_for_slice_pb2
  from google.protobuf import wrappers_pb2
  from google.protobuf import descriptor
  from google.protobuf import message
label_desc: Use image node_id 5 for calling a global function with example usage: plots_as_dataframes(plots) and returns: PlotsDataFrames