Reputation: 4353
I want to use the code from this answer, as it does exactly what I want. I paste it here for the completeness of my question:
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()
I get an error pointing at the ax.set_xticklabels
line, stating that:
TypeError: 'pandas._libs.interval.Interval' object is not subscriptable.
I understand this has been changed after pandas version 0.20
. How can I modify that line to do the same thing but avoid the error?
Upvotes: 2
Views: 100
Reputation: 169334
You can make the Interval object subscriptable by calling str()
on it:
ax.set_xticklabels([str(c)[1:-1].replace(","," to") for c in out.cat.categories])
Upvotes: 2