Reputation: 318
Input:
In [4]: df1
Out[4]:
A B
0 1 1
1 2 2
2 1 3
3 2 4
4 3 5
5 4 6
6 3 7
7 3 8
Here I have to get only the duplicated items in the "A" column of df1. I used df1['A'].duplicated() function it gives me output by dropping one column. But my expected output is as below.
Expected Output:
In [7]: df2
Out[7]:
A B
0 1 1
1 1 3
2 2 2
3 2 4
4 3 5
5 3 7
6 3 8
Upvotes: 1
Views: 119
Reputation: 260335
Use:
df[df['A'].duplicated(keep=False)]
the keep=False
option indicates to flag all duplicates
Upvotes: 1