2

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?

1 Answer 1

2

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])
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that did it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.