如何使用数据帧中的round()函数将多列(0、1、2、3、4)舍入到小数点后2位
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.rand(10,5)*100000).astype(int)
df
0 1 2 3 4
0 49906 39916 72010 53698 47876
预期产量
0 1 2 3 4
0 49906.00 39916.00 72010.00 53698.00 47876.00
更新:
我们可以使用round()转换int数据类型吗?
df = pd.DataFrame(np.random.rand(10,5)*100).astype(int)
print(df.dtypes)
df.round(2)
0 int32
0 1 2 3 4
0 59 84 38 21 97