python - Pandas Drop 部分重复
问题描述
我有 2 个 dfs:
df1:
x y z
0 1 2 r
1 a c 2
2 22 g d
df2:
x y z
0 1 2 r
1 a b 2
2 3 g d
我想在列y
和z
重复时删除。
期望的结果:
x y z
1 a c 2
因为 df1 和 df2 在列中都有相同的值y
并且z
解决方案
cols=['y','z']#columns to check for having same value
df1[~(df1[cols]==df2[cols]).all(axis=1)]#extracting the rows where x and y are `not equal(~)` in both dataframes
推荐阅读
- tensorflow - 是否可以将 TFLite 配置为返回偏差量化为 int8 的模型?
- pm2 - 如何从 systemctl 停止 pm2 进程
- javascript - 过滤javascript异步获取响应
- javascript - SCSS 的 Flexbox 在 Firefox 上正常工作,但在其他浏览器(例如 Chrome、Edge 等)上不能正常工作
- c# - Chrome 未设置会话的 Cookie
- javascript - keep getting empty result on my previous promise
- angular - 如何防止 Angular 工作区中的跨项目?
- ruby-on-rails - Poro 的 FactoryBot 工厂导致未定义的方法“构建”
- python - 导入自己的包和模块的问题
- list - 使用的最佳数据结构