duplicated(self, subset: 'Hashable | Sequence[Hashable] | None' = None, keep: "Literal['first'] | Literal['last'] | Literal[False]" = 'first') -> 'Series'
Considering certain columns is optional.
Only consider certain columns for identifying duplicates, by default use all of the columns.
Determines which duplicates (if any) to mark.
Boolean series for each duplicated rows.
Return boolean Series denoting duplicate rows.
DataFrame.drop_duplicates
Remove duplicate values from DataFrame.
Index.duplicated
Equivalent method on index.
Series.drop_duplicates
Remove duplicate values from Series.
Series.duplicated
Equivalent method on Series.
Consider dataset containing ramen rating.
This example is valid syntax, but we were not able to check execution>>> df = pd.DataFrame({
... 'brand': ['Yum Yum', 'Yum Yum', 'Indomie', 'Indomie', 'Indomie'],
... 'style': ['cup', 'cup', 'cup', 'pack', 'pack'],
... 'rating': [4, 4, 3.5, 15, 5]
... })
... df brand style rating 0 Yum Yum cup 4.0 1 Yum Yum cup 4.0 2 Indomie cup 3.5 3 Indomie pack 15.0 4 Indomie pack 5.0
By default, for each set of duplicated values, the first occurrence is set on False and all others on True.
This example is valid syntax, but we were not able to check execution>>> df.duplicated() 0 False 1 True 2 False 3 False 4 False dtype: bool
By using 'last', the last occurrence of each set of duplicated values is set on False and all others on True.
This example is valid syntax, but we were not able to check execution>>> df.duplicated(keep='last') 0 True 1 False 2 False 3 False 4 False dtype: bool
By setting keep
on False, all duplicates are True.
>>> df.duplicated(keep=False) 0 True 1 True 2 False 3 False 4 False dtype: bool
To find duplicates on specific column(s), use subset
.
>>> df.duplicated(subset=['brand']) 0 False 1 True 2 False 3 True 4 True dtype: boolSee :
The following pages refer to to this document either explicitly or contain code examples using this.
pandas.core.indexes.base.Index.duplicated
pandas.core.series.Series.duplicated
pandas.core.indexes.multi.MultiIndex.duplicated
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them