将小数字显示为零

Lon*_*Rob 2 python pandas

我经常被大熊猫中非常小的浮动值所欺骗,这些浮动值"实际为零".

例如,乍看之下很难看到以下情况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
Run Code Online (Sandbox Code Playgroud)

有没有办法告诉大熊猫显示号码,如5.960464e-08作为0

(显然,这将取决于应用程序是否这是一个好主意,但假设,在我的情况下,它是.)

EdC*_*ica 5

您可以使用set_optionwith '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
Run Code Online (Sandbox Code Playgroud)