【问题标题】:excel file write and read show difficultyexcel文件读写显示难度
【发布时间】:2018-04-20 05:38:43
【问题描述】:

运行代码后我发现了一些问题

import xlsxwriter
import pandas as pd
workbook = xlsxwriter.Workbook('arrays.xlsx')
worksheet = workbook.add_worksheet()
array = [0.222333333333333, 0.048150492835172518, 'a12', 'a13', 'a14']
a=[array]
print('writedata=',a)
row = 0
for col, data in enumerate(a):
workbook.close()

workbook.close()
x = pd.read_excel('arrays.xlsx')
print('readdata=',x)`

写读就像数组

[0.222333333333333, 0.048150492835172518, 'a12', 'a13', 'a14']

但是看完这样的节目

readdata= Empty DataFrame
Columns: [0.222333333333333, 0.04815049283517252, a12, a13, a14]
Index: []

我如何得到这样简单的答案

[0.222333333333333, 0.04815049283517252, a12, a13, a14]

【问题讨论】:

    标签: python python-3.x python-2.7 subprocess xlsxwriter


    【解决方案1】:

    这只是浮点数精度的副作用。

    Excel 使用IEEE 754 Doubles 存储数字。这些数字的精度为 16 位,而您尝试存储的数字 0.048150492835172518 具有 17 位有效数字。

    如果将 0.048150492835172518 插入 Excel 中的单元格,保存文件,关闭文件,再次打开,然后复制数字,您将看到相同的行为。

    【讨论】:

    • jmcnamara 你能在上面的代码中解决这个问题吗?请
    猜你喜欢
    • 1970-01-01
    • 2016-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-01
    • 1970-01-01
    相关资源
    最近更新 更多