@@ -1710,6 +1710,42 @@ def _invalid_indexer(self, form, key):
1710
1710
kind = type (key )))
1711
1711
1712
1712
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
+ """
1713
1749
from collections import defaultdict
1714
1750
counter = defaultdict (lambda : 0 )
1715
1751
for k in self .values :
0 commit comments