How can I change the Pandas plot annotation to an integer?

I used the line of code from this to annotate the total values ​​on top of my columns in the graph, but I can't seem to figure out how to get the result on an integer without decimal places?

ax = df.plot.bar(title="Scores")
for p in ax.patches:
    ax.annotate("%.2f" % p.get_height(), (p.get_x() + p.get_width() / 2., p.get_height()), ha='center', va='center', xytext=(0, 10), textcoords='offset points')

      

Any ideas?

+3


source to share


1 answer


Just convert the number to int

:

ax = df.plot.bar(title="Scores")
for p in ax.patches:
    ax.annotate(str(int(p.get_height())), (p.get_x() + p.get_width() / 2., p.get_height()), ha='center', va='center', xytext=(0, 10), textcoords='offset points')

      




Demo:

+4


source







All Articles