code: def get_pretty_stats(
      stats, recorded_cols=None, num_rows=10, show_tail=True
  ):
      """
      Format and print the last few rows of a statistics DataFrame.
      See the pyfolio project for the data structure.
  
      Parameters
      ----------
      stats: list[Object]
          An array of statistics for the period.
  
      num_rows: int
          The number of rows to display on the screen.
  
      Returns
      -------
      str
  
      """
      if isinstance(stats, pd.DataFrame):
          stats = list(stats.T.to_dict().values())
          stats.sort(key=itemgetter("period_close"))
  
      if len(stats) > num_rows:
          display_stats = (
              stats[-num_rows:] if show_tail else stats[0:num_rows]
          )
      else:
          display_stats = stats
  
      df, columns = prepare_stats(
          display_stats, recorded_cols=recorded_cols
      )
      set_print_settings()
      return df.to_string(columns=columns)
  
imports: import copy
  import csv
  import json
  import numbers
  import os
  import time
  import numpy
  import pandas
  from catalyst.assets._assets import TradingPair
  from catalyst.exchange.utils.exchange_utils import get_algo_folder
  from catalyst.utils.paths import data_root, ensure_directory
  from operator import itemgetter
label_desc: Use image node_id 8 for calling a global function with example usage: get_pretty_stats(stats, recorded_cols, num_rows, show_tail) and returns: df