为什么熊猫在dypes为np.float16
时不舍入数据帧
pd.DataFrame(np.random.rand(10) for x in range(0, 10)).astype(np.float16).round(2)
或
np.round(pd.DataFrame(np.random.rand(10) for x in range(0, 10)).astype(np.float16), 2)
或
pd.DataFrame(np.random.rand(10) for x in range(0, 10)).astype(np.float16).round({0:2, 1:2})
这肯定是以前提过的,但我哪儿都找不到
它是四舍五入。高达float16精度的极限,结果完全符合您的要求。但是,float16精度的限制明显低于熊猫在默认情况下尝试打印的6位有效数字,因此您可以看到一些在打印浮点数字时通常隐藏的表示不精确性
相关问题 更多 >
编程相关推荐