如何使用 pandas 找到重复的名字? [英] How to find duplicate names using pandas?
本文介绍了如何使用 pandas 找到重复的名字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为 name
的包含字符串的 pandas.DataFrame
。
我想获得列中出现多次的名称列表。我试过了:
funcs_groups = funcs.groupby(funcs.name)
funcs_groups [(funcs_groups.count()。name> 1)]
但它不会过滤掉单身人士的名字。
解决方案
如果您想查找重复的行名称(除了我们第一次看到这个),你可以试试这个
In [16]:import pandas as pd
在[17]中:p1 = {'name':'willy','age':10}
在[18]中:p2 = {'name':'willy','age':11}
In [19]:p3 = {'name':'zoe','age':10}
在[20]中:df = pd.DataFrame([p1,p2,p3])
在[21]中:df
Out [21]:
年龄名称
0 10 willy
1 11 willy
2 10 zoe
在[22]中:df.duplicated('name')
Out [22]:
0 False
1 True
2 False
I have a pandas.DataFrame
with a column called name
containing strings.
I would like to get a list of the names which occur more than once in the column. How do I do that?
I tried:
funcs_groups = funcs.groupby(funcs.name)
funcs_groups[(funcs_groups.count().name>1)]
But it doesn't filter out the singleton names.
解决方案
If you want to find the rows with duplicated name (except the first time we see that), you can try this
In [16]: import pandas as pd
In [17]: p1 = {'name': 'willy', 'age': 10}
In [18]: p2 = {'name': 'willy', 'age': 11}
In [19]: p3 = {'name': 'zoe', 'age': 10}
In [20]: df = pd.DataFrame([p1, p2, p3])
In [21]: df
Out[21]:
age name
0 10 willy
1 11 willy
2 10 zoe
In [22]: df.duplicated('name')
Out[22]:
0 False
1 True
2 False
这篇关于如何使用 pandas 找到重复的名字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文