计算字典值的百分比
all_brands_scores = dict(sorted(all_brands_scores.items(), key=lambda item: item[1]))
print(all_brands_scores )
输出:
态 '汤姆森':0,'kano':1,'alienware':1,'razer':1,'google':1, 'lg':2,'hp omen':5,'acer':12,'苹果:13,'Microsoft':13, 'MSI':17,'Samsung':18,'Dell':24,“ Asus”:54,'Lenovo':71,'HP': 104}
我有这个文件(DIC),但不为固定值 如何计算每种笔记本电脑的百分比?
all_brands_scores = dict(sorted(all_brands_scores.items(), key=lambda item: item[1]))
print(all_brands_scores )
output:
{'ADATA': 0, 'GIGABYTE': 0, 'CyberPowerPC': 0, 'Hyundai': 0,
'Thomson': 0, 'KANO': 1, 'Alienware': 1, 'Razer': 1, 'Google': 1,
'LG': 2, 'HP OMEN': 5, 'Acer': 12, 'Apple': 13, 'Microsoft': 13,
'MSI': 17, 'Samsung': 18, 'Dell': 24, 'ASUS': 54, 'Lenovo': 71, 'HP':
104}
I have this file(dic) but not as fixed values
How do I calculate the percentage of each type of laptop ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果要用其百分比替换原始值:
如果您需要一个新的百分比字典:
如果要添加%符号,则必须将值转换为字符串格式
:地方。)
If you want to replace the original values with their percentages:
If you want a new dictionary of percentages:
If you want to add the % symbol, then you will have to convert the values into string format:
(Rounding off the percentages till 2 decimal places.)