pandas.core.groupby.SeriesGroupBy.unique#
- SeriesGroupBy.unique()[源代码]#
为每个组返回唯一值。
它返回每个分组值的唯一值。按出现的顺序返回。基于哈希表的唯一值,因此不排序。
- Returns:
- Series
每个分组值的唯一值。
参见
Series.unique返回 Series 对象中的唯一值。
Examples
>>> df = pd.DataFrame([('Chihuahua', 'dog', 6.1), ... ('Beagle', 'dog', 15.2), ... ('Chihuahua', 'dog', 6.9), ... ('Persian', 'cat', 9.2), ... ('Chihuahua', 'dog', 7), ... ('Persian', 'cat', 8.8)], ... columns=['breed', 'animal', 'height_in']) >>> df breed animal height_in 0 Chihuahua dog 6.1 1 Beagle dog 15.2 2 Chihuahua dog 6.9 3 Persian cat 9.2 4 Chihuahua dog 7.0 5 Persian cat 8.8 >>> ser = df.groupby('animal')['breed'].unique() >>> ser animal cat [Persian] dog [Chihuahua, Beagle] Name: breed, dtype: object