如何对 pyplot 表中的值进行四舍五入

问题描述 投票:0回答:1

我使用 pandas Concat 函数将两个表合并为一个表。然后我将它们放入 pyplot 表中。我最终得到了一个表,其中所有值都有 1 位小数。原始表格在连接之前没有小数点。

如何获得没有小数的表格?

我尝试在连接之前对表中的值进行四舍五入,但这不起作用。

这是我的代码:

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

python matplotlib rounding
1个回答
0
投票
result[["Column1", "Column2"]] = result[["Column1", "Column2"]].round(0).astype(int)

希望可以帮到你

© www.soinside.com 2019 - 2024. All rights reserved.