Skip to content

Commit 79a60b2

Browse files
committed
Add a constructor example
1 parent 8e6adf5 commit 79a60b2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pandas/core/arrays/categorical.py

+7
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,13 @@ def from_codes(cls, codes, categories=None, ordered=None, dtype=None):
667667
An instance of ``CategoricalDtype`` to use for this categorical.
668668
669669
.. versionadded:: 0.24.0
670+
671+
Examples
672+
--------
673+
>>> dtype = pd.api.types.CategoricalDtype(['a', 'b'], ordered=True)
674+
>>> pd.Categorical.from_codes(codes=[0, 1, 0, 1], dtype=dtype)
675+
[a, b, a, b]
676+
Categories (2, object): [a < b]
670677
"""
671678
if dtype is not None:
672679
if categories is not None or ordered is not None:

0 commit comments

Comments
 (0)