Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check if a row in column is unique python Dataframe

I have the following Dataframe:

id1 result
2 0.5
3 1.4
4 1.4
7 3.4
2 1.4

I want to check for every row in the column [‘id1’] if the value is unique

The output should be:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

False
True
True
True
False

The first and the last are False because id 2 exists twice.

I used this method:

bool = df["id1"].is_unique but that checks if the whole column is unique. I want to check it for each row

>Solution :

df['id1'].map(~(df.groupby('id1').size() > 1))
Output
0    False
1     True
2     True
3     True
4    False
Name: id1, dtype: bool
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading