我想使用来自的代码
this answer
,因为它正是我想要的。为了问题的完整性,我将其粘贴在这里:
out = pd.cut(s, bins=[0, 0.35, 0.7, 1], include_lowest=True)
out_norm = out.value_counts(sort=False, normalize=True).mul(100)
ax = out_norm.plot.bar(rot=0, color="b", figsize=(6,4))
ax.set_xticklabels([c[1:-1].replace(","," to") for c in out.cat.categories])
plt.ylabel("pct")
plt.show()
我指出一个错误
ax.set_xticklabels
行,指出:
TypeError: 'pandas._libs.interval.Interval' object is not subscriptable.
我知道这在熊猫版本之后已经改变了
0.20
。我如何修改该行以执行相同的操作但避免错误?