python - 查找数据框中不包含某些值的所有值
问题描述
假设我有一个带有城市和名称的熊猫数据框。当然每个城市都会有很多名字,比如:
Chicago John
Chicago Mary
Chicago Jane
我意识到我有 1000 个不同的城市,但是当我按名称分组并计算有多少城市与约翰相关联时,我只看到 998。我如何找到其中没有任何“约翰”的城市?
解决方案
你可以做
df.groupby('cities').filter(lambda x : (x['name']!='John').all())
推荐阅读
- vba - 什么是 VBA 代码概述的编译错误
- angular - 没有引导 cdn 链接,ngb-rating 不起作用
- c# - 如何使剃须刀页面仅在开发中可用?
- javascript - 如何在另一个数组中获取第三维数组的所有值
- javascript - 基于组件状态的条件模态关闭
- r - R - 更有效的 left_join
- mysql - 按用户ID和日期过滤数据 - Spring Boot
- c# - 如何在 Xaml 中完成“Windows”类型的 DependencyProperty
- google-chrome-extension - 如何构建与当前 chrome 页面并行的注入 chrome 扩展弹出窗口
- javascript - ServiceNow:使用 UI 操作将用户重定向到不同的模块