Skip to content

Commit d86e754

Browse files
committed
Add a constructor example
1 parent b97e8a6 commit d86e754

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pandas/core/arrays/categorical.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,13 @@ def from_codes(cls, codes, categories=None, ordered=None, dtype=None):
634634
An instance of ``CategoricalDtype`` to use for this categorical.
635635
636636
.. versionadded:: 0.24.0
637+
638+
Examples
639+
--------
640+
>>> dtype = pd.api.types.CategoricalDtype(['a', 'b'], ordered=True)
641+
>>> pd.Categorical.from_codes(codes=[0, 1, 0, 1], dtype=dtype)
642+
[a, b, a, b]
643+
Categories (2, object): [a < b]
637644
"""
638645
dtype = CategoricalDtype._from_values_or_dtype(codes, categories,
639646
ordered, dtype)

0 commit comments

Comments
 (0)