Return unique values of Series object. Uniques are returned in order of appearance. Hash table-based unique, therefore does NOT sort. Returns ------- ndarray or ExtensionArray The unique values returned as a NumPy array. See Notes.
(self)
| 2161 | ).__finalize__(self, method="mode") |
| 2162 | |
| 2163 | def unique(self) -> ArrayLike: |
| 2164 | """ |
| 2165 | Return unique values of Series object. |
| 2166 | |
| 2167 | Uniques are returned in order of appearance. Hash table-based unique, |
| 2168 | therefore does NOT sort. |
| 2169 | |
| 2170 | Returns |
| 2171 | ------- |
| 2172 | ndarray or ExtensionArray |
| 2173 | The unique values returned as a NumPy array. See Notes. |
| 2174 | |
| 2175 | See Also |
| 2176 | -------- |
| 2177 | Series.drop_duplicates : Return Series with duplicate values removed. |
| 2178 | unique : Top-level unique method for any 1-d array-like object. |
| 2179 | Index.unique : Return Index with unique values from an Index object. |
| 2180 | |
| 2181 | Notes |
| 2182 | ----- |
| 2183 | Returns the unique values as a NumPy array. In case of an |
| 2184 | extension-array backed Series, a new |
| 2185 | :class:`~api.extensions.ExtensionArray` of that type with just |
| 2186 | the unique values is returned. This includes |
| 2187 | |
| 2188 | * Categorical |
| 2189 | * Period |
| 2190 | * Datetime with Timezone |
| 2191 | * Datetime without Timezone |
| 2192 | * Timedelta |
| 2193 | * Interval |
| 2194 | * Sparse |
| 2195 | * IntegerNA |
| 2196 | |
| 2197 | See Examples section. |
| 2198 | |
| 2199 | Examples |
| 2200 | -------- |
| 2201 | >>> pd.Series([2, 1, 3, 3], name="A").unique() |
| 2202 | array([2, 1, 3]) |
| 2203 | |
| 2204 | >>> pd.Series([pd.Timestamp("2016-01-01") for _ in range(3)]).unique() |
| 2205 | <DatetimeArray> |
| 2206 | ['2016-01-01 00:00:00'] |
| 2207 | Length: 1, dtype: datetime64[us] |
| 2208 | |
| 2209 | >>> pd.Series( |
| 2210 | ... [pd.Timestamp("2016-01-01", tz="US/Eastern") for _ in range(3)] |
| 2211 | ... ).unique() |
| 2212 | <DatetimeArray> |
| 2213 | ['2016-01-01 00:00:00-05:00'] |
| 2214 | Length: 1, dtype: datetime64[us, US/Eastern] |
| 2215 | |
| 2216 | A Categorical will return categories in the order of |
| 2217 | appearance and with the same dtype. |
| 2218 | |
| 2219 | >>> pd.Series(pd.Categorical(list("baabc"))).unique() |
| 2220 | ['b', 'a', 'c'] |
no outgoing calls