def GetPercentileValues(data_frame, percentile):
  """Get the percentile value of each metric for recorded values in dataframe.

  Args:
    data_frame: The dataframe with averages and confidence intervals of each
    story of each run.
    percentile: the percentile to use for determining the upper limits.

  Returns:
    A dictionary with averages and confidence interval ranges calculated
    from the percentile of recent runs.
  """

  if not data_frame.empty:
    avg_df = data_frame.pivot(index='stories', columns='index', values='avg')
    upper_limit = avg_df.quantile(percentile, axis = 1)
    ci_df = data_frame.pivot(index='stories', columns='index', values='ci_095')
    upper_limit_ci = ci_df.quantile(percentile, axis = 1)
    cpu_wall_df = data_frame.pivot(index='stories',
                                   columns='index',
                                   values='cpu_wall_time_ratio')
    upper_limit_cpu_wall = cpu_wall_df.quantile(1 - percentile, axis=1)

    results = {}
    for index in avg_df.index:
      results[index] = {
          'avg': round(upper_limit[index], 3),
          'ci_095': round(upper_limit_ci[index], 3),
          'cpu_wall_time_ratio': round(upper_limit_cpu_wall[index], 3)
      }
    return results