Skip to content

Commit bfa8b7a

Browse files
author
Csaba Farkas
committed
DOC: add docstring for Index.get_duplicates
1 parent dd7f567 commit bfa8b7a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

pandas/core/indexes/base.py

+36
Original file line numberDiff line numberDiff line change
@@ -1710,6 +1710,42 @@ def _invalid_indexer(self, form, key):
17101710
kind=type(key)))
17111711

17121712
def get_duplicates(self):
1713+
"""
1714+
Extract duplicated index elements.
1715+
1716+
This function returns a sorted list of index elements which appear more
1717+
than once in the index.
1718+
1719+
Returns
1720+
-------
1721+
array-like
1722+
List of duplicated indices.
1723+
1724+
See Also
1725+
--------
1726+
:meth:`Index.duplicated` : Return boolean array denoting duplicate values.
1727+
:meth:`Index.drop_duplicates` : Return Index with duplicate values removed.
1728+
1729+
Examples
1730+
--------
1731+
>>> pd.Index([1, 2, 3, 4]).get_duplicates()
1732+
[]
1733+
>>> pd.Index([1, 2, 2, 3, 3, 3, 4]).get_duplicates()
1734+
[2, 3]
1735+
>>> pd.Index([1, 2, 3, 2, 3, 4, 3]).get_duplicates()
1736+
[2, 3]
1737+
>>> pd.Index(['a', 'b', 'b', 'c', 'c', 'c', 'd']).get_duplicates()
1738+
['b', 'c']
1739+
>>> dates = pd.to_datetime(['2018-01-01', '2018-01-02',
1740+
... '2018-01-03', '2018-01-03'],
1741+
... format='%Y-%m-%d')
1742+
>>> pd.Index(pd.to_datetime(dates, format='%Y-%m-%d')).get_duplicates()
1743+
DatetimeIndex(['2018-01-03'], dtype='datetime64[ns]', freq=None)
1744+
1745+
Notes
1746+
-----
1747+
Returns empty list in case all index elements are unique.
1748+
"""
17131749
from collections import defaultdict
17141750
counter = defaultdict(lambda: 0)
17151751
for k in self.values:

0 commit comments

Comments
 (0)