Skip to content

Commit dc37525

Browse files
authored
DOC: add documentation to pandas.core.groupby.SeriesGroupBy.unique (pandas-dev#53210)
* update docstring * make a list of items * update example * update wording in docstring for more specific to groupby unique * update grouped from GroupedBy * correct output
1 parent ccfa9db commit dc37525

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

pandas/core/groupby/generic.py

+39-1
Original file line numberDiff line numberDiff line change
@@ -1245,8 +1245,46 @@ def hist(
12451245
def dtype(self) -> Series:
12461246
return self.apply(lambda ser: ser.dtype)
12471247

1248-
@doc(Series.unique.__doc__)
12491248
def unique(self) -> Series:
1249+
"""
1250+
Return unique values for each group.
1251+
1252+
It returns unique values for each of the grouped values. Returned in
1253+
order of appearance. Hash table-based unique, therefore does NOT sort.
1254+
1255+
Returns
1256+
-------
1257+
Series
1258+
Unique values for each of the grouped values.
1259+
1260+
See Also
1261+
--------
1262+
Series.unique : Return unique values of Series object.
1263+
1264+
Examples
1265+
--------
1266+
>>> df = pd.DataFrame([('Chihuahua', 'dog', 6.1),
1267+
... ('Beagle', 'dog', 15.2),
1268+
... ('Chihuahua', 'dog', 6.9),
1269+
... ('Persian', 'cat', 9.2),
1270+
... ('Chihuahua', 'dog', 7),
1271+
... ('Persian', 'cat', 8.8)],
1272+
... columns=['breed', 'animal', 'height_in'])
1273+
>>> df
1274+
breed animal height_in
1275+
0 Chihuahua dog 6.1
1276+
1 Beagle dog 15.2
1277+
2 Chihuahua dog 6.9
1278+
3 Persian cat 9.2
1279+
4 Chihuahua dog 7.0
1280+
5 Persian cat 8.8
1281+
>>> ser = df.groupby('animal')['breed'].unique()
1282+
>>> ser
1283+
animal
1284+
cat [Persian]
1285+
dog [Chihuahua, Beagle]
1286+
Name: breed, dtype: object
1287+
"""
12501288
result = self._op_via_apply("unique")
12511289
return result
12521290

0 commit comments

Comments
 (0)