Skip to content

Commit 6b544de

Browse files
Dorozhko-Antonjreback
authored andcommitted
DOC: add example about .unique() vs .cat.categories difference
closes #12421 closes #12278
1 parent e45e3b4 commit 6b544de

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

doc/source/categorical.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,23 @@ It's also possible to pass in the categories in a specific order:
182182
indicate an ordered ``Categorical``.
183183

184184

185+
.. note::
186+
187+
The result of ``Series.unique()`` is not always the same as ``Series.cat.categories``,
188+
because ``Series.unique()`` has a couple of guarantees, namely that it returns categories
189+
in the order of appearance, and it only includes values that are actually present.
190+
191+
.. ipython:: python
192+
193+
s = pd.Series(list('babc')).astype('category', categories=list('abcd'))
194+
s
195+
196+
# categories
197+
s.cat.categories
198+
199+
# uniques
200+
s.unique()
201+
185202
Renaming categories
186203
~~~~~~~~~~~~~~~~~~~
187204

0 commit comments

Comments
 (0)