What is the difference between df['id'].duplicated() and df[df.duplicated('id')]?
Do they print same contents?
>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