用法:
classmethod Categorical.from_codes(codes, categories=None, ordered=None, dtype=None)
從代碼和類別或 dtype 中創建分類類型。
如果您已經有代碼和類別/dtype,則此構造函數很有用,因此不需要(計算密集型)分解步驟,這通常在構造函數上完成。
如果您的數據不遵循此約定,請使用普通構造函數。
- codes:array-like of int
一個整數數組,其中每個整數指向 categories 或 dtype.categories 中的一個類別,否則為 -1 表示 NaN。
- categories:index-like,可選
類別的類別。項目必須是唯一的。如果此處未提供類別,則必須在
dtype
中提供類別。- ordered:布爾型,可選
此分類是否被視為有序分類。如果未在此處或
dtype
中給出,則生成的分類將是無序的。- dtype:CategoricalDtype 或“category”,可選
如果
CategoricalDtype
,不能與categories
或ordered
一起使用。
- 分類的
參數:
返回:
例子:
>>> 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']
相關用法
- Python pandas.CategoricalIndex.add_categories用法及代碼示例
- Python pandas.CategoricalIndex.remove_unused_categories用法及代碼示例
- Python pandas.CategoricalIndex.remove_categories用法及代碼示例
- Python pandas.CategoricalIndex.map用法及代碼示例
- Python pandas.CategoricalIndex.rename_categories用法及代碼示例
- Python pandas.Categorical用法及代碼示例
- Python pandas.CategoricalDtype用法及代碼示例
- Python pandas.CategoricalIndex用法及代碼示例
- Python pandas.arrays.IntervalArray.is_empty用法及代碼示例
- Python pandas.DataFrame.ewm用法及代碼示例
- Python pandas.api.types.is_timedelta64_ns_dtype用法及代碼示例
- Python pandas.DataFrame.dot用法及代碼示例
- Python pandas.DataFrame.apply用法及代碼示例
- Python pandas.DataFrame.combine_first用法及代碼示例
- Python pandas.read_pickle用法及代碼示例
- Python pandas.Index.value_counts用法及代碼示例
- Python pandas.DatetimeTZDtype用法及代碼示例
- Python pandas.DataFrame.cumsum用法及代碼示例
- Python pandas.Interval.is_empty用法及代碼示例
- Python pandas.api.indexers.FixedForwardWindowIndexer用法及代碼示例
注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.Categorical.from_codes。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。