我有一个 pandas.DataFrame
,其中有一列名为 name
的列包含字符串。
我想获得在列中多次出现的名称列表。我该怎么做?
我试过了:
funcs_groups = funcs.groupby(funcs.name)
funcs_groups[(funcs_groups.count().name>1)]
但它不会过滤掉单例名称。
最佳答案
如果您想查找名称重复的行(我们第一次看到的除外),您可以试试这个
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
关于python - 如何使用 Pandas 查找重复名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15247628/