pandas 1.4.2

ParametersReturnsBackRef
drop_duplicates(self, keep='first', inplace=False) -> 'Series | None'

Parameters

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

Method to handle dropping duplicates:

inplace : bool, default ``False``

If True , performs operation inplace and returns None.

Returns

Series or None

Series with duplicates dropped or None if inplace=True .

Return Series with duplicate values removed.

See Also

DataFrame.drop_duplicates

Equivalent method on DataFrame.

Index.drop_duplicates

Equivalent method on Index.

Series.duplicated

Related method on Series, indicating duplicate Series values.

Examples

Generate a Series with duplicated entries.

This example is valid syntax, but we were not able to check execution
>>> s = pd.Series(['lama', 'cow', 'lama', 'beetle', 'lama', 'hippo'],
...  name='animal')
... s 0 lama 1 cow 2 lama 3 beetle 4 lama 5 hippo Name: animal, dtype: object

With the 'keep' parameter, the selection behaviour of duplicated values can be changed. The value 'first' keeps the first occurrence for each set of duplicated entries. The default value of keep is 'first'.

This example is valid syntax, but we were not able to check execution
>>> s.drop_duplicates()
0      lama
1       cow
3    beetle
5     hippo
Name: animal, dtype: object

The value 'last' for parameter 'keep' keeps the last occurrence for each set of duplicated entries.

This example is valid syntax, but we were not able to check execution
>>> s.drop_duplicates(keep='last')
1       cow
3    beetle
4      lama
5     hippo
Name: animal, dtype: object

The value False for parameter 'keep' discards all sets of duplicated entries. Setting the value of 'inplace' to True performs the operation inplace and returns None .

This example is valid syntax, but we were not able to check execution
>>> s.drop_duplicates(keep=False, inplace=True)
... s 1 cow 3 beetle 5 hippo Name: animal, dtype: object
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.series.Series.duplicated pandas.core.series.Series.drop pandas.core.frame.DataFrame.duplicated

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/series.py#2106
type: <class 'function'>
Commit: