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

DOC: add missing data handling info to pd.Categorical docstring #36125

Merged
merged 1 commit into from
Sep 5, 2020
Merged
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
13 changes: 13 additions & 0 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,19 @@ class Categorical(NDArrayBackedExtensionArray, PandasObject):
['a', 'b', 'c', 'a', 'b', 'c']
Categories (3, object): ['a', 'b', 'c']

Missing values are not included as a category.

>>> c = pd.Categorical([1, 2, 3, 1, 2, 3, np.nan])
>>> c
[1, 2, 3, 1, 2, 3, NaN]
Categories (3, int64): [1, 2, 3]

However, their presence is indicated in the `codes` attribute
by code `-1`.

>>> c.codes
array([ 0, 1, 2, 0, 1, 2, -1], dtype=int8)

Ordered `Categoricals` can be sorted according to the custom order
of the categories and can have a min and max value.

Expand Down