Examples
Generate a Series with duplicated entries.

In [1]:
import numpy as np
import pandas as pd
In [2]:
s = pd.Series(['cat', 'cow', 'cat', 'dog', 'cat', 'fox'],
              name='animal')
s
Out[2]:
0    cat
1    cow
2    cat
3    dog
4    cat
5    fox
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’.

In [3]:
s.drop_duplicates()
Out[3]:
0    cat
1    cow
3    dog
5    fox
Name: animal, dtype: object

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

In [4]:
s.drop_duplicates(keep='last')
Out[4]:
1    cow
3    dog
4    cat
5    fox
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.

In [5]:
s.drop_duplicates(keep=False, inplace=True)
s
Out[5]:
1    cow
3    dog
5    fox
Name: animal, dtype: object