df =
freq id
11 a
11 b
10 c
9 d
1 e
1 f
我想查看freq
的每个值存储多少次,如果记录一次,请将其删除。
所需的输出:
count =
freq recordings
11 2
10 1
9 1
1 2
然后
df =
freq id
11 a
11 b
1 e
1 f
答案 0 :(得分:3)
根据您的逻辑,您不会在输出中将10
作为freq
,因为它只出现一次:
df[df.groupby('freq')['freq'].transform('count').ne(1)] #change to .gt() for greater than 1
freq id
0 11 a
1 11 b
4 1 e
5 1 f
答案 1 :(得分:2)
IIUC duplicated
df=df[df.freq.duplicated(keep=False)].copy() # add copy for prevent the future copy warning
freq id
0 11 a
1 11 b
4 1 e
5 1 f