ml)
  * [ 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.duplicated  #

DataFrame.  duplicated  (  _ subset  =  None  _ , _ keep  =  'first'  _ )  [
[source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/frame.py#L6828-L6962) #

    

Return boolean Series denoting duplicate rows.

Considering certain columns is optional.

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 mark.

  * ` first  ` : Mark duplicates as ` True  ` except for the first occurrence. 

  * ` last  ` : Mark duplicates as ` True  ` except for the last occurrence. 

  * False : Mark all duplicates as ` True  ` . 

Returns  :

    

Series

    

Boolean series for each duplicated rows.

See also

[ ` Index.duplicated  ` ](pandas.Index.duplicated.html#pandas.Index.duplicated
"pandas.Index.duplicated")

    

Equivalent method on index.

[ ` Series.duplicated  `
](pandas.Series.duplicated.html#pandas.Series.duplicated
"pandas.Series.duplicated")

    

Equivalent method on Series.

[ ` Series.drop_duplicates  `
](pandas.Series.drop_duplicates.html#pandas.Series.drop_duplicates
"pandas.Series.drop_duplicates")

    

Remove duplicate values from Series.

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

    

Remove duplicate values from DataFrame.

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, for each set of duplicated values, the first occurrence is set on
False and all others on True.

    
    
    >>> df.duplicated()
    0    False
    1     True
    2    False
    3    False
    4    False
    dtype: bool
    

By using âlastâ, the last occurrence of each set of duplicated values is
set on False and all others on True.

    
    
    >>> df.duplicated(keep='last')
    0     True
    1    False
    2    False
    3    False
    4    False
    dtype: bool
    

By setting ` keep  ` on False, all duplicates are True.

    
    
    >>> df.duplicated(keep=False)
    0     True
    1     True
    2    False
    3    False
    4    False
    dtype: bool
    

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

    
    
    >>> df.duplicated(subset=['brand'])
    0    False
    1     True
    2    False
    3     True
    4     True
    dtype: bool
    

[ __ previous  pandas.DataFrame.drop_duplicates
](pandas.DataFrame.drop_duplicates.html "previous page") [ next
pandas.DataFrame.equals  __ ](pandas.DataFrame.equals.html "next page")

__ On this page

  * ` DataFrame.duplicated()  `

[ __ Show Source
](../../_sources/reference/api/pandas.DataFrame.duplicated.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.