python:制表时只显示两个十进制数字

2024-10-01 09:26:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我写了一个代码,它解析一些文本文档并显示一些单词出现的频率。在

输出如下:

Counting words by tag
---------------------

modals
per 1000 words                    can  could  shall should   will  would
austen-emma.txt                1.480000 4.350000 1.100000 1.920000 2.900000 4.260000
austen-persuasion.txt          1.090000 4.590000 0.560000 1.920000 1.650000 3.620000
austen-sense.txt               1.500000 4.060000 0.870000 1.640000 2.500000 3.600000
chesterton-ball.txt            1.460000 1.210000 0.510000 0.770000 2.040000 1.440000
chesterton-brown.txt           1.500000 1.990000 0.350000 0.650000 1.290000 1.570000
chesterton-thursday.txt        1.760000 2.180000 0.710000 0.780000 1.570000 1.730000

如您所见,这些数字被四舍五入到百分之一,但我的程序仍然会打印一些过多的零。在

在下面的表格中,代码的末尾是:

^{pr2}$

有人能帮助我改进行打印“%6f%”(单元格),使其不显示结尾的零吗?在

谢谢!在


Tags: 代码txtbytag文本文档单词cancould