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

Method unique

pandas/core/indexes/base.py:2817–2852  ·  view source on GitHub ↗

Return unique values in the index. Unique values are returned in order of appearance, this does NOT sort. Parameters ---------- level : int or hashable, optional Only return values from specified level (for MultiIndex). If int, gets

(self, level: Hashable | None = None)

Source from the content-addressed store, hash-verified

2815 # Uniqueness Methods
2816
2817 def unique(self, level: Hashable | None = None) -> Self:
2818 """
2819 Return unique values in the index.
2820
2821 Unique values are returned in order of appearance, this does NOT sort.
2822
2823 Parameters
2824 ----------
2825 level : int or hashable, optional
2826 Only return values from specified level (for MultiIndex).
2827 If int, gets the level by integer position, else by level name.
2828
2829 Returns
2830 -------
2831 Index
2832 Unique values in the index.
2833
2834 See Also
2835 --------
2836 unique : Numpy array of unique values in that column.
2837 Series.unique : Return unique values of Series object.
2838
2839 Examples
2840 --------
2841 >>> idx = pd.Index([1, 1, 2, 3, 3])
2842 >>> idx.unique()
2843 Index([1, 2, 3], dtype='int64')
2844 """
2845 if level is not None:
2846 self._validate_index_level(level)
2847
2848 if self.is_unique:
2849 return self._view()
2850
2851 result = super().unique()
2852 return self._shallow_copy(result)
2853
2854 def drop_duplicates(self, *, keep: DropKeep = "first") -> Self:
2855 """

Callers 15

intersectionMethod · 0.95
differenceMethod · 0.95
symmetric_differenceMethod · 0.95
test_unique_naMethod · 0.95
get_unique_dtypesMethod · 0.45
setitemMethod · 0.45
_make_selectorsMethod · 0.45
_stack_multi_columnsFunction · 0.45
stack_v3Function · 0.45

Calls 3

_validate_index_levelMethod · 0.95
_viewMethod · 0.95
_shallow_copyMethod · 0.95

Tested by 2

test_unique_naMethod · 0.76