这是一个错误吗?当我四舍五入到小数点后 4 位时,它实际上返回了不同的结果。
import pandas as pd
pd.set_option('precision', 10)
pd.DataFrame([[1.446450001],[1.44645]]).round(4)
结果
0
0 1.4465
1 1.4464
最佳答案
这不是错误 - 相反,这是一个未记录的怪癖。
DataFrame.round 在底层使用 numpy.around,它:
For values exactly halfway between rounded decimal values, Numpy rounds to the nearest even value. Thus 1.5 and 2.5 round to 2.0, -0.5 and 0.5 round to 0.0, etc.
http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.around.html
更多阅读@维基百科:https://en.wikipedia.org/wiki/Rounding#Round_half_to_even
关于python - Pandas 四舍五入,这是一个错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37281044/