pandas.DataFrame.drop_duplicates

pandas 3.1.1 · DataFrame · method

Keep one occurrence of duplicate values or rows by default. Use keep to choose which occurrences survive.

Call syntax

DataFrame.drop_duplicates(subset=None, *, keep='first', inplace=…, ignore_index=False)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
subset Optional
Positional or keyword
Default None
column label or iterable of labels

Restrict the operation to these labels instead of considering the whole object.

keep Optional
Keyword only
Default 'first'
{'first', 'last', False}

Choose which occurrence to retain when values are duplicated or tied.

inplace Optional
Keyword only
bool

Choose whether to change the existing object. Where supported, an in-place call typically returns None.

ignore_index Optional
Keyword only
Default False
bool

Give the resulting axis new integer labels where supported.

Returns

DataFrame or None