pandas 1.4.2

ParametersReturns
duplicated(self, keep='first') -> 'npt.NDArray[np.bool_]'

Duplicated values are indicated as True values in the resulting array. Either all duplicates, all except the first, or all except the last occurrence of duplicates can be indicated.

Parameters

keep : {'first', 'last', False}, default 'first'

The value or values in a set of duplicates to mark as missing.

Returns

np.ndarray[bool]

Indicate duplicate index values.

See Also

DataFrame.duplicated

Equivalent method on pandas.DataFrame.

Index.drop_duplicates

Remove duplicate values from Index.

Series.duplicated

Equivalent method on pandas.Series.

Examples

By default, for each set of duplicated values, the first occurrence is set to False and all others to True:

This example is valid syntax, but we were not able to check execution
>>> idx = pd.Index(['lama', 'cow', 'lama', 'beetle', 'lama'])
... idx.duplicated() array([False, False, True, False, True])

which is equivalent to

This example is valid syntax, but we were not able to check execution
>>> idx.duplicated(keep='first')
array([False, False,  True, False,  True])

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
>>> idx.duplicated(keep='last')
array([ True, False,  True, False, False])

By setting keep on False , all duplicates are True:

This example is valid syntax, but we were not able to check execution
>>> idx.duplicated(keep=False)
array([ True, False,  True, False,  True])
See :

Local connectivity graph

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


File: /pandas/core/indexes/multi.py#1595
type: <class 'function'>
Commit: