我有一个自动生成的 excel 文件,其中偶尔会包含非常大的数字,例如 135061808695
.在 excel 文件中,当您单击单元格时,它会显示完整数字 135061808695
然而,在自动“常规”格式下,数字在视觉上显示为 1.35063E+11
.
当我使用 ExcelFile
时在 Pandas 中,它提取科学记数法中的值 1.350618e+11
而不是完整的 135061808695
.有什么方法可以让 Pandas 在不弄乱 excel 文件的情况下提取全部值(value)?
最佳答案
Pandas 很可能会提取全部值但不会在其默认输出中显示:
df = pd.DataFrame({ 'x':[135061808695.] })
df.x
0 1.350618e+11
Name: x, dtype: float64
标准 python 格式:
print "%15.0f" % df.x
135061808695
或者在 pandas 中,转换为整数类型以获得整数格式:
df.x.astype(np.int64)
0 135061808695
Name: x, dtype: int64
关于python - 使用 Pandas 解析时避免 Excel 的科学记数法舍入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29638263/