Skip to content

Commit 6e42d80

Browse files
committed
Add a constructor example
1 parent c790639 commit 6e42d80

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
@@ -670,6 +670,13 @@ def from_codes(cls, codes, categories=None, ordered=None, dtype=None):
670670
An instance of ``CategoricalDtype`` to use for this categorical.
671671
672672
.. versionadded:: 0.24.0
673+
674+
Examples
675+
--------
676+
>>> dtype = pd.api.types.CategoricalDtype(['a', 'b'], ordered=True)
677+
>>> pd.Categorical.from_codes(codes=[0, 1, 0, 1], dtype=dtype)
678+
[a, b, a, b]
679+
Categories (2, object): [a < b]
673680
"""
674681
if dtype is not None:
675682
if categories is not None or ordered is not None:

0 commit comments

Comments
 (0)