python - 如何使用 Pandas 查找重复名称?

标签 python group-by pandas

我有一个 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/

相关文章:

python - Django如何合并查询结果

python - 从头开始写文件

python - 使用PyInstaller将.py和.txt文件封装成.exe文件

MySQL:在搜索行之后 GROUP BY 是否有效?

python - 使用 Pandas groupby 的 Mathematica GatherBy 函数

python-在for循环中将q写为i的函数

SQL Server 2005 按别名分组

python-3.x - 应用通用函数 (x,y) 从两个现有列创建一个新列,以便我可以在不同列中使用该函数

python - 将值分配给由正则表达式获得的一组列

Python 错误我无法解析 : value of a series is ambiguous