Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Series.duplicated#

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

Indicate duplicate Series values.

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

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

Method to handle dropping duplicates:

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

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

  • False : Mark all duplicates asTrue.

Returns:
Series[bool]

Series indicating whether each value has occurred in thepreceding values.

See also

Index.duplicated

Equivalent method on pandas.Index.

DataFrame.duplicated

Equivalent method on pandas.DataFrame.

Series.drop_duplicates

Remove duplicate values from Series.

Examples

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

>>>animals=pd.Series(['llama','cow','llama','beetle','llama'])>>>animals.duplicated()0    False1    False2     True3    False4     Truedtype: bool

which is equivalent to

>>>animals.duplicated(keep='first')0    False1    False2     True3    False4     Truedtype: bool

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

>>>animals.duplicated(keep='last')0     True1    False2     True3    False4    Falsedtype: bool

By setting keep onFalse, all duplicates are True:

>>>animals.duplicated(keep=False)0     True1    False2     True3    False4     Truedtype: bool

[8]ページ先頭

©2009-2025 Movatter.jp