python - Pandas groupby 仅在观察数超过 X 时显示
问题描述
我有以下代码,我将列预测与列置信度的平均值分组,然后按最高的 10 个进行排序。我需要限制每组内的观察数量,因为有些组非常小,因此不应该出现在上面。
prediction_difficulty = master.groupby(['prediction'])['confidence'].mean().reset_index() prediction_difficulty.sort_values('confidence', ascending=False)[:10]
解决方案
我相信需要GroupBy.head
:
prediction_difficulty.sort_values('confidence',ascending=False).groupby('prediction').head(10)
推荐阅读
- asp.net-core - ActionResult 中的隐式转换运算符
不工作 - unit-testing - 错误:Nil 的未定义方法“x”(编译时类型为 (Point | Nil))
- node.js - 使用“npm init”命令制作 package.json 时出错
- sql - 基于 SELECT 脚本创建 DELETE 脚本
- magento - Magento 2.3.3 客户送货地址名麻烦。“名字”是必需的
- node.js - 在 Ubuntu 服务器上解决 net::ERR_TUNNEL_CONNECTION_FAILED
- android - Android:如果他想使用导航意图,如何向用户显示应用选择器?
- java - 如何在 Spring Boot 2.2 中添加soap 标头以调用soap 端点?
- android - 如何检测 system_server 中的内存泄漏
- arduino - 使用 arduino IDE 的 ESP32 中的 BLE 连接白名单