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

what is the difference between df['id'].duplicated() and df[df.duplicated('id')]

What is the difference between df['id'].duplicated() and df[df.duplicated('id')]?

Do they print same contents?

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

>Solution :

No they won’t.

df['id'].duplicated() returns a Series of booleans depending on whether the IDs are duplicated.

df[df.duplicated('id')] returns a filtered DataFrame where only the rows are kept in which the IDs are duplicated.

Example:

df
  id  col
0  A    0
1  A    1
2  B    2
3  C    3
4  C    4
5  C    5

df['id'].duplicated()
0    False
1     True
2    False
3    False
4     True
5     True

df[df.duplicated('id')]
Name: id, dtype: bool
  id  col
1  A    1
4  C    4
5  C    5
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