Skip to content

Commit

Permalink
add note about missing values to Categorical docstring (pandas-dev#36125
Browse files Browse the repository at this point in the history
)
  • Loading branch information
arw2019 authored and Kevin D Smith committed Nov 2, 2020
1 parent abddc49 commit f8c590f
Showing 1 changed file with 13 additions and 0 deletions.
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

0 comments on commit f8c590f

Please sign in to comment.