python 字典套件统计数据分析

ap_list = {'1': {0: 613, 64: 135},'10': {0: 28, 5: 1, 64: 2674}}
ap_values=[]
suc=0
for k in ap_list.keys():
    ap_values=ap_list[k]
    ap_sum=sum(ap_values.values())
    for v in ap_values.keys():
        if v ==64:
           suc = ap_values[v]
    per = '%.2f%%' %(suc/ap_sum*100)
    countper  = {'100%':per} 
    ap_values.update(countper)
print(k,ap_values)

运行结果如下

{'1': {0: 613, 64: 135, '100%': '18.05%'}, '10': {0: 28, 5: 1, 64: 2674, '100%': '98.93%'}}
©️2020 CSDN 皮肤主题: 我行我“速” 设计师:Amelia_0503 返回首页