gpt4 book ai didi

python Pandas : How to select two equal column per row of a dataframe

转载 作者:行者123 更新时间:2023-11-28 17:36:39 25 4
gpt4 key购买 nike

这是我的数据框“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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com