Python:如何为数据帧的每行选择两个相等的列
这是我的数据帧“dfm”:Python:如何为数据帧的每行选择两个相等的列,python,select,indexing,pandas,group-by,Python,Select,Indexing,Pandas,Group By,这是我的数据帧“dfm”: match org_o group 012 012 Smile Communications 92 012 012 Smile 92 10types 10TYPES 93 10types 10types.com 93 360works 3
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中实现这一点吗?对“组”和“匹配”执行
groupby
,然后对“组织”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