code: def _stringify_slices(
      df: pd.DataFrame,
      slice_key_name: str = _SLICES,
      drop_slices: bool = True,
  ) -> pd.DataFrame:
      """Stringify all the slice columns into one column.
  
      For example, if there are two slice column of 'sex' and 'age', the function
      takes all the slice columns, convert them to string in the format of
      <slice_name>:<slive_value> and concatenate all slice columns using '; '. The
      final result looks like:
        '<slice1_name>:<slice1_value>; <slice2_name>:<slice2_value>.'
  
      Args:
        df: a metrics DataFrame or plots DataFrame.
        slice_key_name: the first level column name that groups all slice columns.
        drop_slices: if True, drops the original slice columns.
  
      Returns:
        A DataFrame with all slice columns stringified and concatenated.
      """
  
      def _concatenate(x):
          return "; ".join(
              f"{col}:{val}"
              for col, val in zip(df[slice_key_name].columns, x)
              if pd.notnull(val)
          )
  
      t = df.slices.agg(_concatenate, axis=1)
      df = (
          df.drop(slice_key_name, axis=1, level=0)
          if drop_slices
          else df.copy()
      )
      df.insert(0, (slice_key_name, _SLICE_STR), t)
      return df.sort_values((slice_key_name, _SLICE_STR))
  
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 7 for calling a global function with example usage: _stringify_slices(df, slice_key_name, drop_slices) and returns: df, str