gpt4 book ai didi

python - Python 中最多保留 16 位小数

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

我在文本文件中有一个具有 16 位十进制精度的数值表,我正在将其读入 Jupyter Notebook 并将其转换为 Pandas DataFrame。如何将十进制模块与 pandas 一起使用来保留文本文件的精度?或者还有什么其他效果会更好的吗?目前,它仅显示小数点后 5-6 位。谢谢!

代码:

from pathlib import Path
folder = Path("C:/This/is/the/path")
file = folder1/"thisfile.txt"
df = loadtxt(file1)
df = pd.DataFrame(df)

输入是一个文本文件:

                2                    2  -14914.622755795561     
3 2 -10563.365160496842
4 2 -6927.2062998872152
5 2 -3886.5429891705344
6 2 -1370.9348975732908

pandas 中的输出如下所示:

0   2.0 2.0 -14914.622756
1 3.0 2.0 -10563.365160
2 4.0 2.0 -6927.206300
3 5.0 2.0 -3886.542989
4 6.0 2.0 -1370.934898

最佳答案

Pandas 不会降低数据的精度,只是在显示时对其进行四舍五入。

要获得 16 位小数精度,请将 float 的显示格式设置为 16 位。

pd.options.display.float_format = '{:,.16f}'.format

导入pandas后使用上述配置。

快乐编码:)

关于python - Python 中最多保留 16 位小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56873342/

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