gpt4 book ai didi

python - 在 pandas 中,您可以按均值聚合并将其舍入到最接近的整数吗?

转载 作者:太空宇宙 更新时间:2023-11-03 12:18:30 25 4
gpt4 key购买 nike

所以我有 169 列被处理为留下 1=yes 和 0=no,现在我需要按平均值聚合 200 万行,以及那一轮结果到最接近的整数,我怎么能得到它?

图像只是显示每列的值为 0 或 1

enter image description here

最佳答案

如果 data 是您的数据框,您只需使用以下方法即可将所有列的平均值作为整数:

data.mean().astype(int)  # Truncates mean to integer, e.g. 1.95 = 1

或者,从版本 0.17.0 开始:

data.mean().round(0)  # Rounds mean to nearest integer, e.g. 1.95 = 2 and 1.05 = 1

关于python - 在 pandas 中,您可以按均值聚合并将其舍入到最接近的整数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45451189/

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