在熊猫数据框中将多列四舍五入为十进制值

时间:2020-06-05 12:15:36

标签: pandas rounding

如何使用数据帧中的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

0 个答案:

没有答案