简体   繁体   English

当 dtype 为 float16 时,为什么 Pandas 不舍入?

[英]Why doesn't Pandas round when dtype is float16?

Why does Pandas not round DataFrames when the dypes are np.float16 ?为什么当 dypes 是np.float16时 Pandas 不舍入数据帧?

pd.DataFrame(np.random.rand(10) for x in range(0, 10)).astype(np.float16).round(2)

Or或者

np.round(pd.DataFrame(np.random.rand(10) for x in range(0, 10)).astype(np.float16), 2)

Or或者

pd.DataFrame(np.random.rand(10) for x in range(0, 10)).astype(np.float16).round({0:2, 1:2})

This must have come up before but I can't find it anywhere?这一定是以前出现过,但我在任何地方都找不到?

It is rounding.四舍五入的。 Up to the limits of float16 precision, the results are exactly what you asked for.达到 float16 精度的限制,结果正是您所要求的。 However, the limits of float16 precision are significantly lower than the 6 significant figures Pandas attempts to print by default, so you see some of the representation imprecision that is usually hidden when printing floating-point numbers.但是,float16 精度的限制明显低于 Pandas 默认尝试打印的 6 个有效数字,因此您会看到一些在打印浮点数时通常隐藏的表示不精确性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM