From 7b9d3d02593d93f687344101e6245835abe1eeb1 Mon Sep 17 00:00:00 2001 From: Dorozhko Anton Date: Tue, 23 Feb 2016 00:24:44 +0600 Subject: [PATCH] add example about .unique() vs .cat.categories difference fix note, add indent to code example fix typo --- doc/source/categorical.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/source/categorical.rst b/doc/source/categorical.rst index 317641f1b3eea..bb8a896a5b91c 100644 --- a/doc/source/categorical.rst +++ b/doc/source/categorical.rst @@ -182,6 +182,18 @@ It's also possible to pass in the categories in a specific order: indicate an ordered ``Categorical``. +.. note:: + + The result of ``Series.unique()`` is not always the same as ``Series.cat.categories``, + because ``Series.unique()`` has a couple of guarantees, namely that it returns categories + in the order of appearance, and it only includes values that are actually present. + + .. ipython:: python + + s = pd.Series(list('babc')).astype('category', categories=list('abcd')) + s.unique() + s.cat.categories + Renaming categories ~~~~~~~~~~~~~~~~~~~