code: def load_results(dir):
      import pandas
  
      monitor_files = glob(osp.join(dir, "*monitor.json")) + glob(
          osp.join(dir, "*monitor.csv")
      )  # get both csv and (old) json files
      if not monitor_files:
          raise LoadMonitorResultsError(
              "no monitor files of the form *%s found in %s"
              % (Monitor.EXT, dir)
          )
      dfs = []
      headers = []
      for fname in monitor_files:
          with open(fname, "rt") as fh:
              if fname.endswith("csv"):
                  firstline = fh.readline()
                  if not firstline:
                      continue
                  assert firstline[0] == "#"
                  header = json.loads(firstline[1:])
                  df = pandas.read_csv(fh, index_col=None)
                  headers.append(header)
              elif fname.endswith("json"):  # Deprecated json format
                  episodes = []
                  lines = fh.readlines()
                  header = json.loads(lines[0])
                  headers.append(header)
                  for line in lines[1:]:
                      episode = json.loads(line)
                      episodes.append(episode)
                  df = pandas.DataFrame(episodes)
              else:
                  assert 0, "unreachable"
              df["t"] += header["t_start"]
          dfs.append(df)
      df = pandas.concat(dfs)
      df.sort_values("t", inplace=True)
      df.reset_index(inplace=True)
      df["t"] -= min(header["t_start"] for header in headers)
      df.headers = headers  # HACK to preserve backwards compatibility
      return df
  
imports: from gym.core import Wrapper
  import time
  from glob import glob
  import csv
  import os.path
  import json
label_desc: Use image node_id 2 for calling a global function with example usage: load_results(dir) and returns: df