code: def _format_comparisons_with_pandas(
      comparisons_json, no_counters, ren_counters
  ):
      pd = _import_pandas()
      df = pd.read_json(StringIO(comparisons_json), lines=True)
      # parse change % so we can sort by it
      df["change %"] = df.pop("change").str[:-1].map(float)
      first_regression = len(df) - df["regression"].sum()
  
      fields = ["benchmark", "baseline", "contender", "change %"]
      if not no_counters:
          fields += ["counters"]
  
      df = df[fields]
      if ren_counters:
          df = df.rename(columns={"counters": "configurations"})
      df = df.sort_values(by="change %", ascending=False)
  
      def labelled(title, df):
          if len(df) == 0:
              return ""
          title += ": ({})".format(len(df))
          df_str = df.to_string(index=False)
          bar = "-" * df_str.index("\n")
          return "\n".join([bar, title, bar, df_str])
  
      return "\n\n".join(
          [
              labelled("Non-regressions", df[:first_regression]),
              labelled("Regressions", df[first_regression:]),
          ]
      )
  
imports: from collections import namedtuple
  from io import StringIO
  import click
  import json
  import logging
  import os
  import pathlib
  import sys
  from .benchmark.codec import JsonEncoder
  from .benchmark.compare import RunnerComparator, DEFAULT_THRESHOLD
  from .benchmark.runner import CppBenchmarkRunner, JavaBenchmarkRunner
  from .compat import _import_pandas
  from .lang.cpp import CppCMakeDefinition, CppConfiguration
  from .utils.cli import ArrowBool, validate_arrow_sources, add_optional_command
  from .utils.lint import linter, python_numpydoc, LintValidationException
  from .utils.logger import logger, ctx
  from .utils.source import ArrowSources
  from .utils.tmpdir import tmpdir
label_desc: Use image node_id 17 for calling a global function with example usage: _format_comparisons_with_pandas(comparisons_json, no_counters, ren_counters) and returns: str, str, str