我想知道如何提取重复信息
I will like to know how to pull out the duplicate information
所以我是 pandas python 的新手。目前,我的任务是确定 "id" 列中的哪些 ID 重复。例如,如果 ID 413 出现超过 1 次,则认为它是重复的。由于有超过 600,000 个 ID,我需要知道它的代码。请帮助!
您可以使用 duplicated
which will return a boolean series to mask the df and then call unique
到 return 重复 ID 数组:
In [196]:
df = pd.DataFrame({'ID':[0,1,1,3,4,5,6,6,6,]})
df
Out[196]:
ID
0 0
1 1
2 1
3 3
4 4
5 5
6 6
7 6
8 6
In [201]:
df[df['ID'].duplicated()]['ID'].unique()
Out[201]:
array([1, 6], dtype=int64)
所以我是 pandas python 的新手。目前,我的任务是确定 "id" 列中的哪些 ID 重复。例如,如果 ID 413 出现超过 1 次,则认为它是重复的。由于有超过 600,000 个 ID,我需要知道它的代码。请帮助!
您可以使用 duplicated
which will return a boolean series to mask the df and then call unique
到 return 重复 ID 数组:
In [196]:
df = pd.DataFrame({'ID':[0,1,1,3,4,5,6,6,6,]})
df
Out[196]:
ID
0 0
1 1
2 1
3 3
4 4
5 5
6 6
7 6
8 6
In [201]:
df[df['ID'].duplicated()]['ID'].unique()
Out[201]:
array([1, 6], dtype=int64)