python - 绘制分类数据的直方图
问题描述
我有一个包含两列的数据集,如下所示:
index Year
0 5 <2012
1 8 >=2012
2 9 >=2012
3 10 <2012
4 15 <2012
... ... ...
171 387 >=2012
172 390 <2012
173 398 <2012
174 403 >=2012
175 409 <2012
我想将它绘制在直方图中。我试过了
plt.style.use('ggplot')
df.groupby(['Year'])\
.Year.count().unstack().plot.bar(legend=True)
plt.show()
但我有一个错误:AttributeError: 'CategoricalIndex' object has no attribute 'remove_unused_levels'
对于
df.groupby(['Year'])\
.Year.count().unstack().plot.bar(legend=True)
我认为这是因为我使用的是分类值。任何帮助将不胜感激。
解决方案
推荐阅读
- kubernetes - 跨命名空间共享 PersistenceVolumeClaim(PVC)
- node.js - 从快速静态服务器提供 ReactJs 包
- android - Cookie 持久性的 GSON 错误
- amazon-web-services - 无法在我的 AWS EC2 实例中进行 ssh
- php - 用户通过身份验证时登录路由中的 Laravel 错误
- ios - 'UITableViewCell' 类型的值没有成员 'Job'
- arrays - 在LUA中将数组转换为字符串
- tableau-api - tableau server 可以将预定报告发送到电子邮件分发列表吗
- azure-service-fabric - 使用 PowerShell 将应用程序洞察添加到 Service Fabric
- html - 网站仅在移动设备上加载一半