Skip to content

Commit 7b2d437

Browse files
arw2019jbrockmendel
authored andcommitted
add note about missing values to Categorical docstring (pandas-dev#36125)
1 parent 0569e29 commit 7b2d437

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pandas/core/arrays/categorical.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,19 @@ class Categorical(NDArrayBackedExtensionArray, PandasObject):
280280
['a', 'b', 'c', 'a', 'b', 'c']
281281
Categories (3, object): ['a', 'b', 'c']
282282
283+
Missing values are not included as a category.
284+
285+
>>> c = pd.Categorical([1, 2, 3, 1, 2, 3, np.nan])
286+
>>> c
287+
[1, 2, 3, 1, 2, 3, NaN]
288+
Categories (3, int64): [1, 2, 3]
289+
290+
However, their presence is indicated in the `codes` attribute
291+
by code `-1`.
292+
293+
>>> c.codes
294+
array([ 0, 1, 2, 0, 1, 2, -1], dtype=int8)
295+
283296
Ordered `Categoricals` can be sorted according to the custom order
284297
of the categories and can have a min and max value.
285298

0 commit comments

Comments
 (0)