Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Index.duplicated#

Index.duplicated(keep='first')[source]#

Indicate duplicate index values.

Duplicated values are indicated asTrue values in the resultingarray. Either all duplicates, all except the first, or all except thelast occurrence of duplicates can be indicated.

Parameters:
keep{‘first’, ‘last’, False}, default ‘first’

The value or values in a set of duplicates to mark as missing.

  • ‘first’ : Mark duplicates asTrue except for the firstoccurrence.

  • ‘last’ : Mark duplicates asTrue except for the lastoccurrence.

  • False : Mark all duplicates asTrue.

Returns:
np.ndarray[bool]

See also

Series.duplicated

Equivalent method on pandas.Series.

DataFrame.duplicated

Equivalent method on pandas.DataFrame.

Index.drop_duplicates

Remove duplicate values from Index.

Examples

By default, for each set of duplicated values, the first occurrence isset to False and all others to True:

>>>idx=pd.Index(['lama','cow','lama','beetle','lama'])>>>idx.duplicated()array([False, False,  True, False,  True])

which is equivalent to

>>>idx.duplicated(keep='first')array([False, False,  True, False,  True])

By using ‘last’, the last occurrence of each set of duplicated valuesis set on False and all others on True:

>>>idx.duplicated(keep='last')array([ True, False,  True, False, False])

By setting keep onFalse, all duplicates are True:

>>>idx.duplicated(keep=False)array([ True, False,  True, False,  True])

[8]ページ先頭

©2009-2025 Movatter.jp