Skip to content

Commit 9fea06c

Browse files
authored
add note about missing values to Categorical docstring (pandas-dev#36125)
1 parent c43652e commit 9fea06c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pandas/core/arrays/categorical.py

+13
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)