如何根据pandas df中的列值查找重复项。如果ann_id的唯一id相同,则尝试获取o/p检查有多少重复项

如何根据pandas df中的列值查找重复项。如果ann_id的唯一id相同,则尝试获取o/p检查有多少重复项,pandas,Pandas,我的df与下面的类似 ann_id unique_id start end 1 apple 0 1 1 apple 2 3 1 apple 4 5 1 apple 6 7 2 apple 0 1 2

我的df与下面的类似

ann_id        unique_id   start     end
1               apple       0       1
1               apple       2       3
1               apple       4       5
1               apple       6       7
2               apple       0       1
2               apple       2       3
2               apple       4       5
2               apple       60      7
1               apple       22      33
1               apple       44      55
1               mango       33      66
1               mango       77      88
1               mango       99      89
2               orange      11      22
2               orange      30      40
2               orange      50      60
我的预期o/p:

ann_id        unique_id   start     end
1               apple       0       1
1               apple       2       3
1               apple       4       5
2               apple       0       1
2               apple       2       3
2               apple       4       5

如果ann\u id的唯一id相同,我将尝试获取o/p检查有多少重复条目

输出

   ann_id unique_id  start  end
0       1     apple      0    1
1       1     apple      2    3
2       1     apple      4    5
4       2     apple      0    1
5       2     apple      2    3
6       2     apple      4    5

在这里,我们检查开始和结束的精确匹配,如果唯一的id匹配它不是连续的,它是一个随机数。谢谢。
   ann_id unique_id  start  end
0       1     apple      0    1
1       1     apple      2    3
2       1     apple      4    5
4       2     apple      0    1
5       2     apple      2    3
6       2     apple      4    5