gpt4 book ai didi

python - 使用 pandas 读取 excel 时精度损失

转载 作者:行者123 更新时间:2023-12-03 21:34:47 28 4
gpt4 key购买 nike

我尝试使用 pandas 将 excel 表读入数据框,但对于浮点列,数据读取不正确。我使用函数 read_excel() 来完成任务

在 excel 中,该值为 225789.479905466,而在数据框中,该值为 225789.47990546614,这使我无法将数据从 excel 导入数据库。

有没有人面临与 pandas.read_exel() 相同的问题。我将 csv 读取到数据框没有问题。

杰里米

最佳答案

我相信这只是浮点错误和/或默认 Excel View 没有显示数字的完整精度。

还要考虑以下几点:

from decimal import Decimal
x = Decimal(225789.479905466)
y = Decimal(225789.47990546614)
print(abs(x - y)/y)
6.444904002816901933512563658E-16

那么 6.5e-14% 的差异是否会有意义地改变您的分析结果?

我敢打赌它不会。

关于python - 使用 pandas 读取 excel 时精度损失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37492173/

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