作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的数据框“dfm”:
match org_o group
012 012 Smile Communications 92
012 012 Smile 92
10types 10TYPES 93
10types 10types.com 93
360works 360WORKS 94
360works 360works.com 94
400 IBM AS/400 Division 36
6c f3f IBM Internal US Division 36
我想选择具有相同“组”编号和相同“匹配”的行。所以结果看起来像这样:
match org_o group
012 012 Smile Communications 92
012 012 Smile 92
10types 10TYPES 93
10types 10types.com 93
360works 360WORKS 94
360works 360works.com 94
有人知道我如何在 python pandas 中做到这一点吗?
最佳答案
对 'group' 和 'match' 执行 groupby
,然后对 'org_o' > 1 的计数执行 filter
:
In [245]:
df.groupby(['group', 'match']).filter(lambda x: x['org_o'].count() > 1)
Out[245]:
match org_o group
0 012 012 Smile Communications 92
1 012 012 Smile 92
2 10types 10TYPES 93
3 10types 10types.com 93
4 360works 360WORKS 94
5 360works 360works.com 94
关于 python Pandas : How to select two equal column per row of a dataframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29793762/
我是一名优秀的程序员,十分优秀!