python - 根据中间数据框删除行
问题描述
df =
freq id
11 a
11 b
10 c
9 d
1 e
1 f
我想查看每个值的freq
存储次数,如果记录一次,请将其删除。期望的输出:
count =
freq recordings
11 2
10 1
9 1
1 2
进而
df =
freq id
11 a
11 b
1 e
1 f
解决方案
根据您的逻辑,您的输出中不会有10
as freq
,因为它只出现一次:
df[df.groupby('freq')['freq'].transform('count').ne(1)] #change to .gt() for greater than 1
freq id
0 11 a
1 11 b
4 1 e
5 1 f
推荐阅读
- css - 如何在反应中更改抽屉组件materialui的背景颜色?
- python - 如何从python中的数组中删除单个反逗号?
- reactjs - 从使用 npm 开始反应时,我安装了 create-react-app 但之后我无法制作反应文件夹
- typescript - 使用 TypeScript 向 Vue 3 添加全局属性
- python - 检查每列中特定值的唯一性
- bash - 如何获取失败的 Ansible 任务的数量并将其传递给下一个 bash 命令?
- python - 你如何读取python子目录中的文件?
- azure - Azure kubernetes - 在 Azure API 管理中注册服务?
- firebase - Flutter 产品列表和使用 Firestore 的详细信息
- angular - 如何根据推送的分支在 .gitlab-ci.yml 中使用不同的脚本