MCPcopy
hub / github.com/pandas-dev/pandas / duplicated

Method duplicated

pandas/core/series.py:2347–2425  ·  view source on GitHub ↗

Indicate duplicate Series values. Duplicated values are indicated as ``True`` values in the resulting Series. Either all duplicates, all except the first or all except the last occurrence of duplicates can be indicated. Parameters ----------

(self, keep: DropKeep = "first")

Source from the content-addressed store, hash-verified

2345 return result
2346
2347 def duplicated(self, keep: DropKeep = "first") -> Series:
2348 """
2349 Indicate duplicate Series values.
2350
2351 Duplicated values are indicated as ``True`` values in the resulting
2352 Series. Either all duplicates, all except the first or all except the
2353 last occurrence of duplicates can be indicated.
2354
2355 Parameters
2356 ----------
2357 keep : {'first', 'last', False}, default 'first'
2358 Method to handle dropping duplicates:
2359
2360 - 'first' : Mark duplicates as ``True`` except for the first
2361 occurrence.
2362 - 'last' : Mark duplicates as ``True`` except for the last
2363 occurrence.
2364 - ``False`` : Mark all duplicates as ``True``.
2365
2366 Returns
2367 -------
2368 Series[bool]
2369 Series indicating whether each value has occurred in the
2370 preceding values.
2371
2372 See Also
2373 --------
2374 Index.duplicated : Equivalent method on pandas.Index.
2375 DataFrame.duplicated : Equivalent method on pandas.DataFrame.
2376 Series.drop_duplicates : Remove duplicate values from Series.
2377
2378 Examples
2379 --------
2380 By default, for each set of duplicated values, the first occurrence is
2381 set on False and all others on True:
2382
2383 >>> animals = pd.Series(["llama", "cow", "llama", "beetle", "llama"])
2384 >>> animals.duplicated()
2385 0 False
2386 1 False
2387 2 True
2388 3 False
2389 4 True
2390 dtype: bool
2391
2392 which is equivalent to
2393
2394 >>> animals.duplicated(keep="first")
2395 0 False
2396 1 False
2397 2 True
2398 3 False
2399 4 True
2400 dtype: bool
2401
2402 By using 'last', the last occurrence of each set of duplicated values
2403 is set on False and all others on True:
2404

Calls 3

_constructorMethod · 0.95
_duplicatedMethod · 0.80
__finalize__Method · 0.80