Primary
Series.drop_duplicates() ⚬|Documentation|1st|20251021004647-00-⌔
pandas.Series.drop_duplicates — pandas 2.3.3 documentation#pandas.Series.drop_duplicates
Series.drop_duplicates(﹡, keep='first', inplace=False, ignore_index=False)Return Series with duplicate values removed.
Parameters:
keep: {‘first’, ‘last’,False}, default ‘first’Method to handle dropping duplicates:
- ‘first’: Drop duplicates except for the first occurrence.
- ‘last’: Drop duplicates except for the last occurrence.
False: Drop all duplicates.
inplace: bool, defaultFalseIf
True, performs operation inplace and returns None.
ignore_index: bool, defaultFalseIf
True, the resulting axis will be labeled 0, 1, …, n - 1.Added in version 2.0.0.
Returns:
Series or None
Series with duplicates dropped or None if
inplace=True.See also:
Index.drop_duplicatesEquivalent method on Index.
DataFrame.drop_duplicatesEquivalent method on DataFrame.
Series.duplicatedRelated method on Series, indicating duplicate Series values.
Series.uniqueReturn unique values as an array.
Examples:
Generate a Series with duplicated entries.
>>> s = pd.Series( ... ["llama", "cow", "llama", "beetle", "llama", "hippo"], name="animal" ... ) >>> s 0 llama 1 cow 2 llama 3 beetle 4 llama 5 hippo Name: animal, dtype: strWith the ‘keep’ parameter, the selection behavior of duplicated values can be changed. The value ‘first’ keeps the first occurrence for each set of duplicated entries. The default value of keep is ‘first’.
>>> s.drop_duplicates() 0 llama 1 cow 3 beetle 5 hippo Name: animal, dtype: strThe value ‘last’ for parameter ‘keep’ keeps the last occurrence for each set of duplicated entries.
>>> s.drop_duplicates(keep="last") 1 cow 3 beetle 4 llama 5 hippo Name: animal, dtype: strThe value
Falsefor parameter ‘keep’ discards all sets of duplicated entries.>>> s.drop_duplicates(keep=False) 1 cow 3 beetle 5 hippo Name: animal, dtype: strPrinted 2026-06-28.
(echo:: @ ᯤ)
Link to original
Secondary
• • •