Make a Categorical type from codes and categories or dtype.
This constructor is useful if you already have codes and categories/dtype and so do not need the (computation intensive) factorization step, which is usually done on the constructor.
If your data does not follow this convention, please use the normal constructor.
An integer array, where each integer points to a category in categories or dtype.categories, or else is -1 for NaN.
The categories for the categorical. Items need to be unique. If the categories are not given here, then they must be provided in dtype.
Whether or not this categorical is treated as an ordered categorical. If not given here or in dtype, the resulting categorical will be unordered.
If CategoricalDtype
, cannot be used together with categories or ordered.
If True, validate that the codes are valid for the dtype. If False, donât validate that the codes are valid. Be careful about skipping validation, as invalid codes can lead to severe problems, such as segfaults.
Added in version 2.1.0.
See also
codes
The category codes of the categorical.
CategoricalIndex
An Index with an underlying Categorical
.
Examples
>>> dtype = pd.CategoricalDtype(["a", "b"], ordered=True) >>> pd.Categorical.from_codes(codes=[0, 1, 0, 1], dtype=dtype) ['a', 'b', 'a', 'b'] Categories (2, object): ['a' < 'b']
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4