Reputation: 579
I have this DataFrame:
A B C D
User1 fake_ne 'Hello' null
User1 year 1987 null
User2 fake_ne 'Hello' null
User2 fake_ne 'Yes' null
User2 fake_year 78 null
I would like to obtain a new Dataframe Pandas which contains all the Users in column A which have more than one entry of 'fake_ne' type in columns B with associate the C value. for instance: DataFrame2
A B C D
User2 fake_ne 'Hello' null
User2 fake_ne 'Yes' null
Upvotes: 0
Views: 28
Reputation: 323316
We can do it by two steps filter then check duplicated
s=df.loc[df.B=='fake_ne']
s[s.A.duplicated(keep=False)]
Out[497]:
A B C D
2 User2 fake_ne 'Hello' NaN
3 User2 fake_ne 'Yes' NaN
Upvotes: 1