gpt4 book ai didi

python - 当浮点精度很重要时如何减去两列

转载 作者:行者123 更新时间:2023-12-01 08:13:24 25 4
gpt4 key购买 nike

我试图减去数据框中的两列,但它给我的所有值都提供相同的结果?

这是我的数据:

        a           b   
0 0.35805 -0.01315
1 0.35809 -0.01311
2 0.35820 -0.01300
3 0.35852 -0.01268

我尝试了 here 中建议的方法,但它在所有行中对我重复相同的结果。

最佳答案

更像是精度问题,我总是使用十进制

from decimal import *
df.z.map(Decimal)-df.dist.map(Decimal)
Out[189]:
0 0.3711999999999999796246319406
1 0.3712000000000000195232718880
2 0.3712000000000000177885484121
3 0.3712000000000000056454840802
dtype: object

关于python - 当浮点精度很重要时如何减去两列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55093945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com