我编写了以下代码以舍入数据帧中的浮动值 a
a
a = pd.DataFrame([[1.2,3.4],[1.4,4.6]]) a = a.apply(round)
但我得到的结果如下:
0 1 0 1.0 3.0 1 1.0 5.0
为什么函数返回的是四舍五入的浮点值而不是整数?
此外,在按如下方式应用时,其行为也不同:
round(0.5) >>0
x= [1.4,2.5,3.6] list(map(round,x)) >>[1, 2, 4]
为什么会出现这种异常?