我有一个看起来像这样的数据数组:
#API name, min, max, average
['findProductByPartNumber', '336.0', '336.0', '336.0']
['findProductByPartNumber', '336.0', '339.0', '337.5']
['findProductByPartNumber', '336.0', '339.0', '338.0']
['findProductByPartNumber', '336.0', '341.0', '338.75']
['findProductByPartNumber', '336.0', '353.0', '341.6']
['findProductById', '841.0', '841.0', '841.0']
['findProductByPartNumber', '336.0', '920.0', '438.0']
['findProductByPartNumber', '336.0', '944.0', '510.29']
['findProductByPartNumber', '336.0', '952.0', '565.5']
['findProductByPartNumber', '336.0', '975.0', '611.0']
['findProductsByCategory', '113.0', '113.0', '113.0']
['findProductById', '161.0', '841.0', '501.0']
['findProductByPartNumber', '255.0', '975.0', '575.4']
我想要做的是,对于每个单独的 API,生成如下内容:
API, Min, Max, Average, 90th Percentile
findProductByPartNumber, 278.69, 770.25, 458.69, 565.5
findProductById, 373.0, 841.0, 571.67, 501.0
findProductsByCategory, 112.33, 187.17, 154.46, 167.75
这是上面每个 API 的汇总结果。在 Python 中执行此操作的最佳方法是什么?
编辑:
我有以下 Java 代码可以满足我的要求。Java 是我最好的语言,我正在尝试学习 Python,但我不熟悉数据结构。
double[] apiValues = new double[3];
apiValues[0] = Double.valueOf(min);
apiValues[1] = Double.valueOf(max);
apiValues[2] = Double.valueOf(average);
parseAPILogs.registerAPI(name, apiValues);
...
...
private static void registerAPI(String apiName, double[] apiValues) {
if(!averagePerAPI.containsKey(apiName)) {
APIData data = new APIData();
data.addValues(apiValues);
averagePerAPI.put(apiName, data);
} else {
averagePerAPI.get(apiName).addValues(apiValues);
}
}
APIData Java 类在这里有点大,但你可以看到我的想法。