gpt4 book ai didi

python - 如何舍入 Pandas 数据框的所有列?

转载 作者:行者123 更新时间:2023-12-01 01:21:26 25 4
gpt4 key购买 nike

我的代码:

>>> mean = all_data.groupby(['Id'])[features].agg('mean').reset_index()
>>> print(mean)

0 0.000000
1 362.000000
2 0.000000
3 0.000000
4 60.093750
5 0.000000

我想将这些数字四舍五入到小数点后两位,例如:

0          0.00
1 362.00
2 0.00
3 0.00
4 60.09
5 0.00

最佳答案

在最近的 pandas 版本中,您可以df.round(2)

关于python - 如何舍入 Pandas 数据框的所有列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53801897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com