ZBLOG

threshold = 5 size_of_groups = ['Schooling'] # 修改为所需的组大小列表 merged_groups = [group if group > threshold else 0 for group in size_of_groups] categories = ['0-5', '5-10', '10-15', '15+'] # 修改为所需的分类标签 count_over_threshold = sum(group for group in si

根据报错信息看起来是因为size_of_groups列表中的元素是字符串而不是整数导致的。你需要确保size_of_groups列表中的元素都是整数类型才能进行比较操作。可以尝试将列表中的元素改为整数,或者在比较时将字符串转换为整数。

以下是一个可能的修改方法:

threshold = 5
size_of_groups = [int(group) for group in size_of_groups]  # 将字符串转换为整数
merged_groups = [group if group > threshold else 0 for group in size_of_groups]
categories = ['0-5', '5-10', '10-15', '15+']
count_over_threshold = sum(group for group in size_of_groups if group > threshold)
merged_groups.append(count_over_threshold)
plt.pie(merged_groups, labels=categories)
plt.show()

这样修改后,应该就可以正常运行了。请注意确认输入数据和其他相关代码是否正确。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:http://sdn.0voice.com/?id=2588

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?