def wa_result_to_power_perf_table(df, performance_metric, index):
    table = df.pivot_table(index=index + ['iteration'],
                           columns='metric', values='value').reset_index()
    result_mean = table.groupby(index).mean()
    result_std = table.groupby(index).std()
    result_std.columns = [c + ' std' for c in result_std.columns]
    result_count = table.groupby(index).count()
    result_count.columns = [c + ' count' for c in result_count.columns]
    count_sqrt = result_count.apply(lambda x: x.apply(math.sqrt))
    count_sqrt.columns = result_std.columns  # match column names for division
    result_error = 1.96 * result_std / count_sqrt  # 1.96 == 95% confidence interval
    result_error.columns = [c + ' error' for c in result_mean.columns]

    result = pd.concat([result_mean, result_std, result_count, result_error], axis=1)
    del result['iteration']
    del result['iteration std']
    del result['iteration count']
    del result['iteration error']

    updated_columns = []
    for column in result.columns:
        if column == performance_metric:
            updated_columns.append('performance')
        elif column == performance_metric + ' std':
            updated_columns.append('performance_std')
        elif column == performance_metric + ' error':
            updated_columns.append('performance_error')
        else:
            updated_columns.append(column.replace(' ', '_'))
    result.columns = updated_columns
    result = result[sorted(result.columns)]
    result.reset_index(inplace=True)

    return result
dataset/ETHPy150Open ARM-software/workload-automation/wlauto/instrumentation/energy_model/__init__.py/wa_result_to_power_perf_table/original