Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to round values in pyplot table

I joined two tables into one using pandas Concat function. I then put them in a pyplot table. I end up with a table where all the values have 1 decimal. The original tables did not have the decimal before concatenating.

How can I get a table without decimals?

I tried rounding the values in the tables before concatenating but this does not work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is my code:

frames = [country_tab, country_birth_tab] 

result = pd.concat(frames, axis=1)
#print(result)

ax = plt.subplot(111, frame_on=False) # no visible frame
ax.xaxis.set_visible(False)  # hide the x axis
ax.yaxis.set_visible(False)  # hide the y axis

table2 = table(ax, result) 
table2.auto_set_font_size(False)
table2.set_fontsize(16)
table2.scale(4,4)

This is the output

>Solution :

For your case result = result.astype(int) also should work. astype(int) is help to convert your float to int. So your columns will be integer.

Also that line can work your code.

result[["Column1", "Column2"]] = result[["Column1", "Column2"]].astype(int)

So your final code is :

frames = [country_tab, country_birth_tab] 

result = pd.concat(frames, axis=1)

result = result.astype(int)

ax = plt.subplot(111, frame_on=False) # no visible frame
ax.xaxis.set_visible(False)  # hide the x axis
ax.yaxis.set_visible(False)  # hide the y axis

table2 = table(ax, result) 
table2.auto_set_font_size(False)
table2.set_fontsize(16)
table2.scale(4,4)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading