Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixups for categoricals #8153

Merged
merged 7 commits into from
Sep 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions doc/source/10min.rst
Original file line number Diff line number Diff line change
Expand Up @@ -652,11 +652,11 @@ Since version 0.15, pandas can include categorical data in a ``DataFrame``. For
# Alternative: df["grade"] = df["raw_grade"].astype("category")
df["grade"]

# Rename the levels
df["grade"].cat.levels = ["very good", "good", "very bad"]
# Rename the categories inplace
df["grade"].cat.categories = ["very good", "good", "very bad"]

# Reorder the levels and simultaneously add the missing levels
df["grade"].cat.reorder_levels(["very bad", "bad", "medium", "good", "very good"])
# Reorder the categories and simultaneously add the missing categories
df["grade"] = df["grade"].cat.set_categories(["very bad", "bad", "medium", "good", "very good"])
df["grade"]
df.sort("grade")
df.groupby("grade").size()
Expand Down
21 changes: 14 additions & 7 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -555,26 +555,33 @@ Categorical

.. currentmodule:: pandas.core.categorical

If the Series is of dtype ``category``, ``Series.cat`` can be used to access the the underlying
``Categorical``. This accessor is similar to the ``Series.dt`` or ``Series.str``and has the
If the Series is of dtype ``category``, ``Series.cat`` can be used to change the the categorical
data. This accessor is similar to the ``Series.dt`` or ``Series.str`` and has the
following usable methods and properties (all available as ``Series.cat.<method_or_property>``).

.. autosummary::
:toctree: generated/

Categorical.levels
Categorical.categories
Categorical.ordered
Categorical.reorder_levels
Categorical.remove_unused_levels
Categorical.rename_categories
Categorical.reorder_categories
Categorical.add_categories
Categorical.remove_categories
Categorical.remove_unused_categories
Categorical.set_categories
Categorical.codes

To create a Series of dtype ``category``, use ``cat = s.astype("category")``.

The following methods are considered API when using ``Categorical`` directly:
The following two ``Categorical`` constructors are considered API but should only be used when
adding ordering information or special categories is need at creation time of the categorical data:

.. autosummary::
:toctree: generated/

Categorical
Categorical.from_codes
Categorical.codes

``np.asarray(categorical)`` works by implementing the array interface. Be aware, that this converts
the Categorical back to a numpy array, so levels and order information is not preserved!
Expand Down
Loading