将小数字显示为零 - python

我经常被熊猫中很小的浮点值(实际上是零)所迷惑。

例如,很难一眼看到以下Series的情况:

are_they_zero
a   -5.960464e-08 # This number is small
b   -2.384186e+07 # This one isn't
c    2.384186e-07
d   -5.960464e+08
e    8.940697e-08

有没有办法告诉熊猫将5.960464e-08之类的数字显示为0

(显然,这取决于应用程序是否是个好主意,但就我而言,假设是这样。)

python大神给出的解决方案

您可以将set_option'display.chop_threshold'一起使用来处理此问题:

In [20]:
pd.set_option('display.chop_threshold', 0.001)
df

Out[20]:
   are_they_zero
a              0
b  -2.384186e+07
c              0
d  -5.960464e+08
e              0