* [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ DataFrame ](../frame.html)
  * pandas.DataF... 

#  pandas.DataFrame.drop_duplicates  #

DataFrame.  drop_duplicates  (  _ subset  =  None  _ , _ *  _ , _ keep  =
'first'  _ , _ inplace  =  False  _ , _ ignore_index  =  False  _ )  [
[source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/frame.py#L6731-L6826) #

    

Return DataFrame with duplicate rows removed.

Considering certain columns is optional. Indexes, including time indexes are
ignored.

Parameters  :

    

**subset** column label or sequence of labels, optional

    

Only consider certain columns for identifying duplicates, by default use all
of the columns.

**keep** {âfirstâ, âlastâ, ` False  ` }, default âfirstâ

    

Determines which duplicates (if any) to keep.

  * âfirstâ : Drop duplicates except for the first occurrence. 

  * âlastâ : Drop duplicates except for the last occurrence. 

  * ` False  ` : Drop all duplicates. 

**inplace** bool, default ` False  `

    

Whether to modify the DataFrame rather than creating a new one.

**ignore_index** bool, default ` False  `

    

If ` True  ` , the resulting axis will be labeled 0, 1, â¦, n - 1.

Returns  :

    

DataFrame or None

    

DataFrame with duplicates removed or None if ` inplace=True  ` .

See also

[ ` DataFrame.value_counts  `
](pandas.DataFrame.value_counts.html#pandas.DataFrame.value_counts
"pandas.DataFrame.value_counts")

    

Count unique combinations of columns.

Examples

Consider dataset containing ramen rating.

    
    
    >>> 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, it removes duplicate rows based on all columns.

    
    
    >>> df.drop_duplicates()
        brand style  rating
    0  Yum Yum   cup     4.0
    2  Indomie   cup     3.5
    3  Indomie  pack    15.0
    4  Indomie  pack     5.0
    

To remove duplicates on specific column(s), use ` subset  ` .

    
    
    >>> df.drop_duplicates(subset=['brand'])
        brand style  rating
    0  Yum Yum   cup     4.0
    2  Indomie   cup     3.5
    

To remove duplicates and keep last occurrences, use ` keep  ` .

    
    
    >>> df.drop_duplicates(subset=['brand', 'style'], keep='last')
        brand style  rating
    1  Yum Yum   cup     4.0
    2  Indomie   cup     3.5
    4  Indomie  pack     5.0
    

[ __ previous  pandas.DataFrame.drop  ](pandas.DataFrame.drop.html "previous
page") [ next  pandas.DataFrame.duplicated  __
](pandas.DataFrame.duplicated.html "next page")

__ On this page

  * ` DataFrame.drop_duplicates()  `

[ __ Show Source
](../../_sources/reference/api/pandas.DataFrame.drop_duplicates.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.